DataGrid.SelectedIndex Property

Gets or sets the index of the selected item in the DataGrid control.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

[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)

Property Value

The index of the selected item in the DataGrid control.

Exception typeCondition

ArgumentOutOfRangeException

The specified index is less than -1.

Use the SelectedIndex property to determine the index of the item selected by the user in the DataGrid control. You can also use this property to programmatically specify which item is selected in the DataGrid control.

To deselect an item in the DataGrid control, set this property to -1.

The following code example demonstrates how to use the SelectedIndex property to determine the index number of the selected item in the DataGrid control. It also shows how to select and deselect an item programmatically.

No code example is currently available or this language may not be supported.

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show: