asp.net.ph

ListControl.SelectedIndex Property

System.Web.UI.WebControls Namespace   ListControl Class


Sets or retrieves an integer specifying the index of the selected item in a ListControl.

Syntax


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

Property Value


intIndex Integer specifying the ordinal index of the selected item in a ListControl.

The property is read/write with a default value of -1, which indicates that nothing is selected.

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 list items in a ListControl are indexed in the order in which they are defined, starting with an index of zero.

Use the SelectedIndex property to specify or determine the index of the selected item in a single-selection ListControl. This index can then be used to access the properties of the selected list item from the Items collection.

If SelectionMode is set to multiple, this property returns only the index of the first selected item ( the lowest index in the selection ).

By default, the first item in the list 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.

Example

Below are links to code examples that illustrate using a list control's SelectedIndex property in varied scenarios.

Calendar Date Selection Modes
Run Sample | View Source
Custom Paging Using Primary Key Values
Run Sample | View Source
Using the ListControl DataTextField Property
Run Sample | View Source
See Also

ListControl Members   SelectedIndexChanged   SelectedItem   SelectedValue 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