asp.net.ph

DataGrid.SelectedIndex Property

System.Web.UI.WebControls Namespace   DataGrid Class


Sets or retrieves the index of the selected item in the DataGrid control.

Syntax


Script DataGrid.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 item in the DataGrid 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 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.

Example

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 ( );
}
  C# VB

 Show me 

See Also

DataGrid Members 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