Rowupdating gridview findcontrol

19-May-2020 12:44

In data driven web sites, users are normally allowed to view data and administrators are allowed to add, edit or delete data.

In this tutorial I will show you how you can create an editable Grid View control for administrators to modify database records directly into the Grid View control.

In the Page_Load event, you simply load your data from the database and bind it with the Grid View control as shown below: For brevity I am not storing connection string in the web.config and also not using any Data Access Component.

To do this we first need to obtain the reference of the current row by using its index no as shown in the first line below.

In the above code, I set two properties Show Edit Button and Show Cancel Button of Command Field.

These properties will automatically render Edit, Update and Cancel buttons inside Grid View column.

To get the Primary Key reference we can use the Data Keys collection of the Grid View.

This collection only requires the row index no and it will give us the primary key.

To do this we first need to obtain the reference of the current row by using its index no as shown in the first line below.In the above code, I set two properties Show Edit Button and Show Cancel Button of Command Field.These properties will automatically render Edit, Update and Cancel buttons inside Grid View column.To get the Primary Key reference we can use the Data Keys collection of the Grid View.This collection only requires the row index no and it will give us the primary key.The example shown here is for a Grid View, but the same types of event handlers must be implemented in roughly the same way for other data controls including the Form View, Details View, and List View. This is the final Grid View markup, so you can see the event handlers we’re going to implement.