aspxtreme

Allowing Users to Edit Rows in a GridView Control

Controls You Can Use on Web Forms   ASP.NET Data Controls   GridView Control


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:

  1. 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;
    GridView AutoGenerateEditButton Example
    Run Sample | View Source
  2. 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.

    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

Now let's take a closer look at how all these are done.



Books and more ...


Suggested Reading

Need a break ?


More ...
Back to top

Check out related books at Amazon

© 2000-2008 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 aspxtreme