The rowupdating event
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.But ensure that the control/link is inside the Grid View, only then can we cast sender as Grid View.This code is a bit complex but just add it knowing that we may refer to it in the future.A Grid View Sort Event Args object is passed to the event-handling method, which enables you to determine the sort expression for the column and to indicate that the selection operation should be canceled.To cancel the selection operation, set the property of the Grid View Sort Event Args object to true.
This enables you to provide an event-handling method that performs a custom routine, such as canceling the sorting operation, whenever this event occurs.If user clicks the Cancel button while Grid View is in editing mode, you need to Cancel the Editing process and also need to reset the Edit Index property to -1 in the Row Canceling Edit event of the Grid View control as shown below: The last step is to handle the Row Updating event to actually update the back end database.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.NET 2.0 Grid View control to view, add, update, and delete data in a SQL database. In this code below code, you see database table columns binding with the bound fields and formatting is provided using the template fields.The below is my connection string which is stored in web.config file. If you are using my database, just copy and paste the code or use the attached application.
Search for the rowupdating event:
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.