System.Web.UI.WebControls Namespace GridView Class
.NET Framework version 2.0
Sets or retrieves the index of the row to edit in a GridView control.
Script |
GridView.EditIndex [ = intIndex ] |
This property can only be used programmatically; it cannot be set when declaring the control.
intIndex |
Integer specifying the ordinal index of the row to edit. |
The property is read/write with no default value.
Exception Type |
Condition |
ArgumentOutOfRangeException |
The given index is set to less than -1 or greater than or equal to the rows count of the GridView. |
Use the EditIndex property to programmatically specify or determine the index of the row to edit in a GridView control. This index can then be used to access the methods and properties of the row.
NOTE: Like most indexes in ASP.NET, EditIndex is zero-based, meaning the first row in the collection returns an index of 0.
EditIndex returns a value of -1 if no row is in edit mode. Always test this value before attempting to reference any row selected for editing. When this property is set to the index of a row in the control, that row enters edit mode.
In edit mode, each field in the row that is not read-only displays an input control appropriate for the field's data type, such as a TextBox or CheckBox control, to allow the user to modify the field's value.
You can programmatically deselect a row in edit mode by setting the EditIndex property to -1.
NOTE: The GridView control has a built-in editing feature that automatically sets this property. This property is typically used only when you need to programmatically determine which row is being edited or when you are adding your own custom editing functionality to the GridView control.
The following examples demonstrate using the EditIndex property to programmatically set the index of the row to update in a GridView control.