asp.net.ph

DropDownList.SelectedIndex Property

System.Web.UI.WebControls Namespace   DropDownList Class


Sets or retrieves the index of the selected item in a DropDownList control.

Syntax


Inline <asp:dropdownlist selectedindex = intIndex ... >
Script DropDownList.SelectedIndex [ = intIndex ]

Property Value


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.

Exceptions


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.

Remarks

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.

Example

The following examples demonstrate using the SelectedIndex property of a DropDownList control.

Calendar Date Selection Modes
Run Sample | View Source
CompareValidator Example
Run Sample | View Source
Custom Paging Using Primary Key Values
Run Sample | View Source
See Also

DropDownList Members   SelectedIndexChanged   SelectedItem Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph