Gridview rowupdating event from code

Posted by / 30-Jan-2020 08:11

NET page that will handle different Grid View events to provide complete editing functionality.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.These properties will automatically render Edit, Update and Cancel buttons inside Grid View column.I am using Template Field’s Item Template and Edit Item Template for providing read only and editing interface of the same column in the Grid View.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.By using the Grid View Row object we can find the reference of any control in the row in which user is editing the data.This collection only requires the row index no and it will give us the primary key.Last line of the following code is calling a local method for updating the database and passing all the parameters to this method.

In the code below I do get the Country ID and Region ID but they are the original values not the new ones selectedfrom the Edit Mode row.

The visitors to a web site can typically be divided into two groups: the users and the administrators.

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

Please keep in mind that there are many different ways to update the database using the Grid View control depending on the type of data you are updating and the functionality the user need and there are many solutions to achieve the same end result.

In the above tutorial I tried to give you one of the easiest solutions and I hope you can go explore Grid View control editing further after learning the basics from this tutorial.

gridview rowupdating event from code-49gridview rowupdating event from code-83gridview rowupdating event from code-40

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.