Populating ListBoxes

One of the most common tasks you will encounter with using WebControls is populating their values from a data source. DropDownList, in particular, is one of the controls that most commonly needs to be populated from a data source of some kind. To wrap up this chapter, we're going to cover three different ways of populating DropDownList controls using ASP.NET. This example uses WebControls, but you could easily convert to using HtmlControls using the same syntax. The complete source code for the ASP page and codebehind is in Listings 5.3 and 5.4.

Listing 5.3. Populating drop-down lists (DropDownList.aspx).
 <%@ Page language="c#" ...

Get ASP.NET by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.