System.Web.UI.WebControls Namespace GridView Class
.NET Framework version 2.0
Sets or retrieves the index of the selected row in the GridView control.
Script |
GridView.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 row in the GridView control. |
The property is read/write with no default value.
Use the SelectedIndex property to determine the index of the row selected by the user in the GridView control. You can also use this property to programmatically specify which row is selected in the GridView control.
To deselect a row in the GridView control, set this property to -1.
The following example demonstrates how to use the SelectedIndex property to determine the index number of the selected row in the GridView control.
void getSelected ( Object src, EventArgs e ) {
string id = myGrid.DataKeys [ myGrid.SelectedIndex ].Value.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 ).Value.ToString ( )
Dim query As String = "Select * FROM Products where ProductId = '" + id + "'"
myDetailsList.DataSource = fetchData ( query, "gear" )
myDetailsList.DataBind ( )
End Sub |
|
C# |
VB |
SelectedDataKey SelectedRow Allowing Users to Select Rows in a GridView Control