Gridview rowupdating event in c
I will be using Sql objects directly into methods to keep the example simple and straight forward.
In practical scenario you should use your existing architecture to populate and update the data.
When Update link of the Grid View will be clicked (in edit mode), On Row Updating event will fire that will call Update Record method.
In this method, we have to get changed values of Text Box and Drop Down list and also we need the primary key value for the record that is being edited.
To populate the Grid View, I am calling Bind Data() method from Page_Load event after checking Is Post Back property of the page, so the Grid View will only be populated when there is no postback on the page (when the page loads for the first time).After that again, I am doing the same thing that I had done in Cancel Record method, I mean setting Edit Index property of the Grid View to -1 and rebinding the data again by calling Bind Data() method.When Delete link of the Grid View will be clicked, it will confirm the user whether they really want to Delete the record, if they will click OK, it will fire On Row Deleting event of the Grid View that will call Delete Record method.This will make sure that Bind Data() method will not fire when you are going to edit, update or delete the record.In Bind Data() method, I am getting the data from database using Sql objects and specifying the Data Source property of the Grid View to the Pages Data table of the Data Set.