Gridview rowupdating cancel

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.

Last line of the following code is calling a local method for updating the database and passing all the parameters to this method.

Please keep in mind that there are many different ways to update the database using the Grid View control depending on the type of data you are updating and the functionality the user need and there are many solutions to achieve the same end result.

In the above tutorial I tried to give you one of the easiest solutions and I hope you can go explore Grid View control editing further after learning the basics from this tutorial.

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.

gridview rowupdating cancel-36gridview rowupdating cancel-65gridview rowupdating cancel-72

It contains Some bound Fields and one checkbox field. It succesfully enters edit mode and when i hit update the Datasource updates but the control will not return to readonly mode.To get the Primary Key reference we can use the Data Keys collection of the Grid View.This collection only requires the row index no and it will give us the primary key.I have gone far enough to figure out the problem is caused by the Checkbox field.The checkbox works and passes the correct true/false value to the datasource but will not bind after update When I Make it readonly and remove that value from my Stored Procedure the Gridview control works normal. Usually when you have a Gridview than can be edited you click the edit button and all the editable fields become Textboxes and the Checkbox is Enabled.

Leave a Reply

  1. australia newcastle dating 07-Jan-2020 22:17

    Steven Ward is the star, host, and executive producer of the VH1 "Tough Love" series.