System.Web.UI.WebControls Namespace DataGrid Class
Sets or retrieves the index of the selected item in the DataGrid control.
Script |
DataGrid.SelectedIndex [ = intIndex ] |
This property can only be used programmatically; it cannot be set when declaring the control.
intIndex |
Integer specifying the index of the selected item in the DataGrid control. |
The property is read/write with no default value.
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 example demonstrates how to use the SelectedIndex property to determine the index number of the selected item in the DataGrid control.
void getSelected ( Object src, EventArgs e ) {
string id = myGrid.DataKeys [ myGrid.SelectedIndex ].ToString ( );
string query = "Select * FROM Products where ProductId = '" + id + "'";
myDetailsList.DataSource = fetchData ( query, "gear" );
myDetailsList.DataBind ( );
}
Sub getSelected ( src As Object, e As EventArgs )
Dim id As String = myGrid.DataKeys ( myGrid.SelectedIndex ).ToString ( )
Dim query As String = "Select * FROM Products where ProductId = '" + id + "'"
myDetailsList.DataSource = fetchData ( query, "gear" )
myDetailsList.DataBind ( )
End Sub |
|
C# |
VB |
Show me
DataGrid Members