System.Web.UI.HtmlControls Namespace
Allows programmatic access to the HTML <select> element on the server.
Visibility |
Constructor |
Parameters |
public |
HtmlSelect |
( )
|
Visibility |
Name |
Value Type |
Accessibility |
public |
DataMember
|
String |
[ Get , Set ] |
public |
DataSource
|
Object |
[ Get , Set ] |
public |
DataSourceID
|
String |
[ Get , Set ] |
public |
DataTextField
|
String |
[ Get , Set ] |
public |
DataValueField
|
String |
[ Get , Set ] |
public |
InnerHtml
|
String |
[ Get , Set ] |
public |
InnerText
|
String |
[ Get , Set ] |
public |
Items
|
ListItemCollection |
[ Get ] |
public |
Multiple
|
Boolean |
[ Get , Set ] |
public |
Name
|
String |
[ Get , Set ] |
public |
SelectedIndex
|
Int32 |
[ Get , Set ] |
public |
Size
|
Int32 |
[ Get , Set ] |
public |
Value
|
String |
[ Get , Set ] |
|
Use the HtmlSelect control to create a box with selectable options.
You can specify the selectable items in the control by declaratively setting HTML <option> elements between the opening and closing <select> tags at design time, or by dynamically adding options to the control's Items collection.
Each option item is of type System.Web.UI.WebControls.ListItem, and inherits the properties of that class.
To specify the text that is displayed for each item in the control, you can simply place text between the opening and closing <option> tags at design time, or set the Text property of the item at run time.
You can also associate a value with the option element that is different from its text, by setting the Value property of the element.
To select an item from the list by default, set the Selected property of the item to true.
You can control the appearance and behavior of the HtmlSelect control by setting the Size and Multiple properties. The Size property specifies the height ( in rows ) of the control, while the Multiple property specifies whether more than one item can be concurrently selected in the HtmlSelect.
By default, HtmlSelect displays as a drop-down list box. If you enable multiple selections or specify a size that is greater than one and less than the number of items in the control, the control renders as a scrollable list box.
To determine the selected item in a single-selection HtmlSelect control, use either the Value property, or the SelectedIndex property to get the index of the selected item. SelectedIndex is helpful when you need to access the item from the collection.
To determine the selected items from an HtmlSelect control that allows multiple selections, iterate through the Items collection and test the ListItem.Selected property of each item.
The HtmlSelect control allows you to bind the control to a data source. Use the DataSource property to specify the data source to bind to. You can also specify which field in the data source binds to the ListItem.Text and ListItem.Value properties of an item in the control by setting the DataTextField and DataValueField properties, respectively. If the data source contains multiple sources of data, use the DataMember property to specify the specific source to bind to the control. For example, if you have a DataSet with multiple tables, you must specify which table to bind to the control with the DataMember property.
For examples illustrating use of this control, see the individual member types of this class. For syntax information, see HtmlSelect in ASP.NET Syntax for HTML Controls.
ListBox DropDownList