ListControl.SelectedIndex Property
Assembly: System.Web (in system.web.dll)
[ThemeableAttribute(false)] [BindableAttribute(true)] public: virtual property int SelectedIndex { int get (); void set (int value); }
/** @property */ public int get_SelectedIndex () /** @property */ public void set_SelectedIndex (int value)
public function get SelectedIndex () : int public function set SelectedIndex (value : int)
Not applicable.
Property Value
The lowest ordinal index of the selected items in the list. The default is -1, which indicates that nothing is selected.Use this property to determine the index of the currently selected item in the list if the list control allows only one selection. If the list control supports multiple selections, use this property to determine the lowest index of the selected items.
The value of the SelectedIndex property is not specifically saved on postback. It is restored on postback using the SelectedValue property. For example, if the SelectedValue property is 4, on postback, the SelectedIndex property is set to the index of the ListItem object that has a Value property of 4. If more than one ListItem object has a Value property of 4, the first item in the Items collection is selected.
This property cannot be set by themes or style sheet themes. For more information, see ThemeableAttribute and Introduction to ASP.NET Themes.
| Topic | Location |
|---|---|
| How to: Determine the Selection in List Web Server Controls | Building ASP .NET Web Applications |
| How to: Determine the Selection in List Web Server Controls | Building ASP .NET Web Applications |
| How to: Set the Selection in List Web Server Controls (Visual Studio) | Building ASP .NET Web Applications in Visual Studio |
The following example demonstrates how to use SelectedIndex to determine the lowest index of the selected items in the CheckBoxList.