System.Web.UI.WebControls Namespace DropDownList Class
Sets or retrieves the index of the selected item in a DropDownList control.
Inline |
<asp:dropdownlist selectedindex = intIndex ... > |
Script |
DropDownList.SelectedIndex [ = intIndex ] |
intIndex |
Integer specifying the ordinal index of the selected item in the list. |
The property is read/write with a default value of 0, which selects the first item in the list.
Exception Type |
Condition |
ArgumentOutOfRangeException |
The given index is set to less than -1 or greater than or equal to the items count of the list. |
The SelectedIndex property is mainly used to programmatically specify or determine the index of the selected item in a single-selection DropDownList control. This index can then be used to access the properties of the selected option from the Items collection.
Options in a DropDownList are indexed in the order in which they are defined.
NOTE: Like most indexes in ASP.NET, SelectedIndex is zero-based, meaning the first item in the collection returns an index of 0.
By default, the first item in the list is initially selected.
NOTE: An item is always selected in the DropDownList control. You cannot deselect every item in the list at the same time.
The following examples demonstrate using the SelectedIndex property of a DropDownList control.
DropDownList Members SelectedIndexChanged SelectedItem