The
ListBox Control Appearance
The ListBox control is typically used to display more than one item at once. You can control the look of the list in these ways:
-
Number of rows displayed. You can set the control to display a specific number of items. If the control contains more items than that, it displays a vertical scroll bar.
-
Height and width. You can set the size of the control using pixels. In that case, the control ignores the number of rows you have set and displays as many as will fit into the height of the control. Some browsers do not support setting the height and width in pixels and will use the row count setting.
As with other Web server controls, you can use style objects to specify the appearance of the control. For details, see
Items
The ListBox control is actually a container for one or more list items. Each list item is an object of type
Property | Description |
---|---|
|
The text displayed in the list. |
|
The value associated with an item. Setting this property allows you to associate a value with a specific item without displaying it. For example, you can set the Text property to the name of a U.S. state and the Value property to its postal abbreviation. |
|
A Boolean value indicating whether the item is selected. |
To work with items programmatically, you work with the
The currently selected item is available in the ListBox control's
Single vs. Multiple Selection
Users can normally select a single item in the list by clicking it. If you set the ListBox control to allow multiple selections, users can hold down the CTRL or SHIFT key while clicking to select multiple items.
Binding Data to the Control
You can use a ListBox Web server control to list options that are made available to the page using a data source control. Each item in the ListBox control corresponds to an item — typically a row — in the data source.
The control displays one field from the source. Optionally, you can bind the control to a second field to set the value (which is not displayed) of an item.
As with other server controls, you can bind any control properties, such as the color or size of the control, to data. For details, see How to: Populate List Web Server Controls from a Data Source.
ListBox Events
The ListBox control raises an event (the
![]() |
---|
The ability of a ListBox control to post to the server when it is checked requires that the browser support ECMAScript (JScript, JavaScript) and that scripting be enabled on the user's browser. |
See Also
