The GridView supports in-place editing of individual rows in the control.
This is enabled basically by providing a command-type button control for each row that, essentially, serves to specify the row to edit. The GridView also encapsulates the functionality to visually highlight the row to edit, using the EditRowStyle property.
When an individual row is set into edit mode, the values from the data source are by default displayed in editable text box controls in which the user can change values. The GridView, though, supports using an EditItemTemplate in a TemplateField, that is rendered for whichever row is currently in edit mode. This provides a means for customizing the behavior of edit controls and, optionally, for validating user input.
Providing edit mode controls in the GridView can be done in either of two ways:
- using the automatic editing feature of the grid, in which the edit button controls for each row are autogenerated and rendered via a separate CommandField object;
- using customized <asp:Button>, <asp:LinkButton> or <asp:ImageButton> controls that are bound to a field in the data source, and which are rendered either via a ButtonField or in the ItemTemplate of a GridView's TemplateField.
NOTE: In this scenario, the buttons simply select the row for editing. You must provide a means to actually update the record in the data source after the user edits the row in the GridView.
Now let's take a closer look at how all these are done. 