Working with the ListBox Control

The ListBox control is similar to the DropDownList control with two important differences. First, the ListBox control requires more screen real estate because it always displays a certain number of list items. Furthermore, unlike the DropDownList control, the ListBox control enables a user to select multiple items.

The page in Listing 10.11 illustrates how you can enable a user to select a single item from a ListBox control (see Figure 10.10).

Figure 10.10. Displaying list items with the ListBox control.

image

Listing 10.11. ShowListBox.aspx

The ListBox control in Listing 10.11 includes a Rows property. The

Get ASP.NET 4 Unleashed 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.