GridView Editing / Updating / Deleting:
One of the feature of GridView is to support "in place Editing" what even data we are presenting to user can also be allowed with rich Editing (deleting also).
Gridview provides a property called EditIndex whose default value is "-1". When this value is changed to some record then that record of GridView is set to be in Editing Mode.
In Editing mode all fields of GridView provide different presentation.
BoundField --- displays data in Textboxes
TemplateField -- displays EditItemTemplate instead of ItemTemplate , CommandField displays Update, Cancel instead of Edit, Update option.
CommandField is one more GridViewField which is provide Exclusively for Editing purpose and which has different arguments and Events to support Editing. Combining all these fields along with Edit Index property will provide the required functionality.
1) In a new form create Button ,Gridview and Write code under Button Click event to set Data Object to it.
2) Set Auto Generate Columns false . So, that we can specify our own column information.
Go to Source view and write code / markup for Gridview ensuring that they are with editing behavior.
3) For all command field buttons GridView provides events where we have to write our implementations .
for Edit – RowEditing event
for Delete – RowDeleting event
for Update – RowUpdating event
for Cancel – RowCancelingEdit event
In this article I'm trying to explain how to do editing and updating and cancelling edit with simple example. Hope this will help you who are trying to do this..