System.Web.UI.HtmlControls Namespace HtmlSelect Class
Sets or retrieves the source of information to bind to the HtmlSelect control.
Inline |
<select datasource = enumerable ... > |
Script |
HtmlSelect.DataSource [ = enumerable ] |
enumerable |
An IEnumerable collection that contains the data to bind to the control. |
The property is read/write with no default value.
Use the DataSource property to specify the source of the data to bind to the HtmlSelect control.
NOTE: The data source must be an object that implements the System.Collections.IEnumerable interface, such as a DataView, an ArrayList, or a Hashtable.
If the data source contains a single column or field, the records in the data source are then automatically used to populate the option elements of the select box.
If the data source contains multiple sets of data, such as a DataSet with multiple tables, use the DataMember property to specify which table in the data source to bind to the control.
You can also bind the HtmlSelect to a data source that contains multiple columns or fields. In this case, you specify which fields from the data source to bind to the ListItem.Text and ListItem.Value properties of each item in the control by setting the DataTextField and DataValueField properties, respectively.
The following example demonstrates how to programmatically set the DataSource property at run time to specify the source of information to bind to the HtmlSelect control.
mySelect.DataSource = myDataSet.Tables [ "Types" ].DefaultView;
Show me
HtmlSelect Members DataTextField DataValueField DataMember