System.Web.UI.HtmlControls.HtmlSelect.SelectedIndex Property

Gets or sets the ordinal index of the selected item in an System.Web.UI.HtmlControls.HtmlSelect control.

Syntax

[System.ComponentModel.Browsable(false)]
[System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
public virtual int SelectedIndex { set; get; }

Value

Documentation for this section has not yet been entered.

Remarks

The HtmlSelect.SelectedIndex property is commonly used to determine the index of the selected item in a single-selection System.Web.UI.HtmlControls.HtmlSelect control. This index can then be used to retrieve the item from the HtmlSelect.Items collection.

If the HtmlSelect.Multiple property is set to true, indicating that multiple items can be concurrently selected, the HtmlSelect.SelectedIndex property contains the index of the first selected item. To determine the selected items from an System.Web.UI.HtmlControls.HtmlSelect control that allows multiple simultaneous selections, iterate through the HtmlSelect.Items collection and test the System.Web.UI.WebControls.ListItem.Selected property of each item.

Note:

It is possible to have no item selected. If no item is selected, the HtmlSelect.SelectedIndex property contains a value of -1. This commonly occurs when the page first loads and an item is not selected by default. Provide code to test this value before referencing the item in the HtmlSelect.Items collection. Otherwise, an exception is thrown if the index is out of the range of the collection.

By default, the System.Web.UI.HtmlControls.HtmlSelect control is displayed as a drop-down list box. If you allow multiple selections (by setting the HtmlSelect.Multiple property to true) or specify a height greater than one row (by setting the HtmlSelect.Size property to a value greater than 1), the control is displayed as a list box. If a drop-down list box is displayed, an item is always selected. If a list box is displayed, you can programmatically clear the selection from all items by setting the HtmlSelect.SelectedIndex property to -1.

Requirements

Namespace: System.Web.UI.HtmlControls
Assembly: System.Web (in System.Web.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0