asp.net.ph

HtmlSelect.SelectedIndex Property

System.Web.UI.HtmlControls Namespace   HtmlSelect Class


Sets or retrieves the ordinal index of the selected item in the HtmlSelect control.

Syntax


Inline <select selectedindex = intIndex ... >
Script HtmlSelect.SelectedIndex [ = intIndex ]

Property Value


intIndex Integer specifying the ordinal index of the selected item.

The property is read/write with no default value.

Remarks

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.

See Also

HtmlSelect Members 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