asp.net.ph

GridView.SelectedIndex Property

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.

Syntax


Script GridView.SelectedIndex [ = intIndex ]

This property can only be used programmatically; it cannot be set when declaring the control.

Property Value


intIndex Integer specifying the index of the selected row in the GridView control.

The property is read/write with no default value.

Exceptions


Exception Type Condition
ArgumentOutOfRangeException The given index is less than -1.

Remarks

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.

Example

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 ( );
}
  C# VB
Run Sample | View Source
See Also

SelectedDataKey   SelectedRow   Allowing Users to Select Rows in a GridView Control Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph