DropDownList Web Server Control Overview
TheWeb server control allows users to select an item from a predefined list. It differs from the Web server control in that the list of items remains hidden until users click the drop-down button. In addition, the DropDownList control differs from the ListBox control in that it does not support multi-selection mode.
You can control the look of the DropDownList control by setting its height and width in pixels. Some browsers do not support setting the height and width in pixels and will use the row-count setting instead.
You cannot specify the number of items that are displayed in the list when users click the drop-down button. The length of the displayed list is determined by the browser.
As with other Web server controls, you can use style objects to specify the appearance of the DropDownList control. For details, see.
The DropDownList control is actually a container for the list items, which are of type. Each ListItem object is a separate object with its own properties. These properties are described in the following table.
Specifies the text that is displayed in the list.
Contains the value that is 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.
Indicates whether the item is selected by means of a Boolean.
To work with list items programmatically, use thecollection of the DropDownList control. The Items collection is a standard collection, and you can add item objects to it, delete items, clear the collection, and so on.
The currently selected item is available in the DropDownList control'sproperty.
You can use a DropDownList Web server control to list options that are made available to the page using a data source control. Each item in the DropDownList 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 of an item, which does not display.
As with other Web server controls, you can bind any control properties, such as the color or size of the control, to data. For details, see.
The DropDownList control raises an event — theevent — when users select an item. By default, this event does not cause the page to be posted to the server, but you can cause the control to force an immediate post by setting the property to true.