|
The DropDownList control provides a single-select drop-down list. The following sample illustrates using a simple DropDownList control.
C# DropDownList1.aspx
The following sample illustrates using data binding to a static ArrayList
with a DropDownList control.
C# DropDownList2.aspx
In addition to programmatically databinding, as shown in the example above, you can also
data bind a DropDownList declaratively to a data source control. The following example
shows a DropDownList bound to the Authors table in the Pubs database.
C# DropDownList3.aspx
Note that the DropDownList includes DataTextField and DataValueField properties for
specifying the field value to render for the Text and Value properties of its list items,
respectively. The value of the currently selected item is exposed through the SelectedValue
property of DropDownList. All controls that derive from ListControl (includes DropDownList)
follow this pattern.
|