Asp net c gridview onrowupdating

03 Jan

I have specified Data Key Names as Auto ID, the primary key of the database table.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.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.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.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.

asp net c gridview onrowupdating-10asp net c gridview onrowupdating-62asp net c gridview onrowupdating-23

When Cancel link is clicked on Grid View in edit mode, On Row Canceling Edit event will fire that will call Cancel Record method.

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.

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.