DropDownList Web Server Control Overview
The DropDownList Web server control enables users to select a single item from a predefined drop-down list.
This topic contains:
The DropDownList Web server control enables users to select an item from a predefined list. It differs from the ListBox Web server control in that the list of items remains hidden until users click the drop-down button. In addition, the DropDownList control does not support multi-selection mode.
Modifying the Appearance of the DropDownList Control
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.
The DropDownList control is actually a container for the list items, which are of type ListItem. 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 enables 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 color and the Value property to its hexadecimal representation.
Indicates whether the item is currently selected.
To work with list items programmatically, use the Items collection 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.
Binding Data to the Control
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 in the data source, typically an individual data record.
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 is not displayed.
As with other Web server controls, you can bind any control properties to data, such as the color or size of the control. For details, see How to: Populate List Web Server Controls from a Data Source.
The DropDownList control raises the SelectedIndexChanged event when users select an item. By default, this event does not cause the page to be posted to the server. However, you can cause the control to force an immediate post by setting the AutoPostBack property to true.