Gridview onrowupdating

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.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.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.In this article, I am going to take a simple database table that has following fields: Auto ID - Int, Auto Increment, Primary Key Page Name - Varchar(50) Page Description - Varchar(500) Active - Bit(1) In this article, I am not going to explain the workings of Sql objects but focusing on the events and methods of the Grid View that will help us in updating and deleting the records.

Then I have several methods attached with following events Get video of hundreds of ASP. On Row Editing - Edit Record On Row Cancel Edit - Cancel Record On Row Updating - Update Record On Row Deleting - Delete Record As I set Auto Generate Columns property to false so I am going to manually write the fields name that I need to appear in the way I want.

To get the Primary key, I have used Data Keys property of the Grid View with the index of the row, being edited and stored into a integer variable after parsing.

Now I have declared a Grid View Row variable named row and stored the current row being edited into it.

With the help row variable, I am going to find all the controls placed under that row in edit mode using Find Control property.

After finding the controls I am using them to pass their values to the parameter of the Sql Command object that is ultimately updating the records into database.