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.

[Visual Basic]
Public Overridable Property SelectedIndex As Integer
public virtual int SelectedIndex {get; set;}
public: __property virtual int get_SelectedIndex();
public: __property virtual void set_SelectedIndex(int);
public function get SelectedIndex() : int;
public function set SelectedIndex(int);

Property Value

The index of the selected item in the DataGrid control.


Exception Type Condition
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.


Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

DataGrid Class | DataGrid Members | System.Web.UI.WebControls Namespace