The ListBox Web Control

The ListBox control represents a vertical sequence of items displayed in a scroll­able window. As shown in the following code, ListBox allows single or multiple item selection and exposes its contents by using the familiar Items collection:

<asp:listbox runat="server" id="theListBox" 
    rows="5" selectionmode="Multiple" />

You can determine the height of the control by using the Rows property. As you might have guessed, the height is measured in numbers of rows rather than in pixels or percentages.

When it comes to data binding, the ListBox control behaves like the other controls discussed earlier in the chapter—that is, it supports properties such as DataSource, DataMember, DataTextField, DataValueField, and DataText­FormatString ...

Get Building Web Solutions with ASP.NET and ADO.NET 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.