ASP.NET HtmlSelect Control
Definition and Usage
The HtmlSelect control is used to control the <select> element. In HTML, the <select> element is used to create a dropdown list.
Properties
Properties | Description |
---|---|
Attributes | Returns all attribute names and value pairs of the element. |
DataMember | The name of the data table to be used. |
DataSource | The data source to be used. |
DataTextField | The field in the data source to be displayed in this drop-down list. |
DataValueField | Specifies the field in the data source for each selectable option in this drop-down list. |
Disabled | Boolean value indicating whether the control is disabled. The default is false. |
id | The unique id of the control. |
InnerHtml | Sets or returns the content between the start and end tags of the HTML element. Special characters are not automatically converted to HTML entities. |
InnerText | Sets or returns all text between the start and end tags of the HTML element. Special characters are automatically converted to HTML entities. |
Items | The list of items in the drop-down list. |
Multiple | Whether multiple items can be selected at the same time. |
OnServerChange | The name of the function to be executed when the selected item is changed. |
runat | Specifies that the control is a server control. It must be set to "server". |
SelectedIndex | The index number of the currently selected item. |
Size | The number of visible items in the drop-down list. |
Style | Sets or returns the CSS properties applied to the control. |
TagName | Returns the tag name of the element. |
Value | The value of the currently selected item. |
Visible | Boolean value indicating whether the control is visible. |
Example
- HTMLSelect
- In this example, we declare an HtmlImage control and an HTMLSelect control in the .aspx file. Then we will modify the src attribute of the HtmlImage control based on the user's selection. The value selected in the HtmlSelect control determines which image is displayed.