asp.net.ph

GridView.EditIndex Property

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.

Syntax


Script GridView.EditIndex [ = intIndex ]

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

Property Value


intIndex Integer specifying the ordinal index of the row to edit.

The property is read/write with no default value.

Exceptions


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.

Remarks

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.

Example

The following examples demonstrate using the EditIndex property to programmatically set the index of the row to update in a GridView control.

Selecting Rows to Edit in a GridView Using a ButtonField
Run Sample | View Source
Selecting Rows to Edit in a GridView Using a TemplateField
Run Sample | View Source
See Also

GridView Members   RowCancelingEdit   RowEditing   EditRowStyle   Allowing Users to Edit Items 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