System.Web.UI.HtmlControls Namespace HtmlSelect Class
Sets or retrieves the ordinal index of the selected item in the HtmlSelect control.
Inline |
<select selectedindex = intIndex ... > |
Script |
HtmlSelect.SelectedIndex [ = intIndex ] |
intIndex |
Integer specifying the ordinal index of the selected item. |
The property is read/write with no default value.
The SelectedIndex property is mainly used to determine the index of the selected item in a single-selection HtmlSelect control. This index can then be used to access the properties of the selected option from the Items collection.
If multiple selection is enabled, this property returns only the index of the first selected item.
By default, HtmlSelect is displayed as a single-selection drop-down list, and the first item is initially selected. When multiple selection is enabled, though, it is possible to have no item selected. This commonly occurs when the page first loads and no item is selected by default.
SelectedIndex returns a value of -1 if no item is selected. Always provide code to test this value before attempting to reference any selected item in your code.
If a multiple selection list box is displayed, you can programmatically deselect all items by setting the SelectedIndex property to -1.
NOTE: Like most indexes in ASP.NET, SelectedIndex is zero-based, meaning the first item in the collection returns an index of 0.
HtmlSelect Members