This example shows how to edit and update records in a Grid View in ASP. This example is helpful in situations where an administrator needs to edit several records from the database.For demonstration I have created a database (named Database.mdf) in which we have a table named tbl_Employee.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.
Now I will show you the C# code behind file of the above ASP.
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.
When I click on the edit button the update and cancel button appear.