System.Web.UI.WebControls Namespace GridView Class
.NET Framework version 2.0
Returns a GridViewRow object that represents the selected row in the GridView control.
Script |
[ GridViewRow variable = ] GridView.SelectedRow |
This property can only be used programmatically; it cannot be set when declaring the control.
The property is read only with no default value.
Use the SelectedRow property to get a GridViewRow object that represents the selected row in the GridView control. This object can then be used to access the properties of the selected row.
The following example demonstrates how to programmatically set the style properties of the SelectedRow in the GridView control at run time.
void chgSelectedProps ( Object src, EventArgs e ) {
if ( myGrid.SelectedRow != null ) {
myGrid.SelectedRow.BackColor = System.Drawing.Color.Khaki;
myGrid.SelectedRow.ForeColor = System.Drawing.Color.Maroon;
myGrid.SelectedRow.Font-Bold = true;
}
}
Sub chgSelectedProps ( src As Object, e As EventArgs )
If Not ( myGrid.SelectedRow Is Nothing ) Then
myGrid.SelectedRow.BackColor = System.Drawing.Color.Khaki
myGrid.SelectedRow.ForeColor = System.Drawing.Color.Maroon
myGrid.SelectedRow.Font-Bold = True
End If
End Sub |
|
C# |
VB |
GridViewRow SelectedDataKey SelectedIndex Allowing Users to Select Rows in a GridView Control