This documentation is archived and is not being maintained.

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);
}
<asp:DataGrid SelectedIndex="Int32" />

Property Value

Type: System::Int32
The index of the selected item in the DataGrid control.

ExceptionCondition
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.

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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