Gridview rowupdating cancel event

Hi stefbek97, Something in your question is not adding up.I took your Grid View, created an Object Data Source that matched the Fields that the Grid View was displaying and bound the Grid View to it so that I can see what you're "seeing".In the same way you can put any kind of Validation controls inside Edit Item Template to validate the form element while user will click Update link.For Page Name and Page Description field I want them to appear in the Text Box in edit view, so I have specified text property of Text Box as the field value in Edit Item Template and for Active field, I want it to appear as the Drop Down List so I have specified the Selected Value property as the value of the Active 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.I change the values and click update but the gridview stays in Edit mode instead of canging back to Readonly and displaying the new results.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.So I have to specify how I want them to appear in the normal view and edit view.

When Edit link of the Grid View will be clicked then On Row Editing event will fire that will call Edit Record method.

Now let’s start with putting the Grid View on page. Data Key Names="Auto ID" Auto Generate Edit Button="True" On Row Editing="Edit Record" On Row Canceling Edit="Cancel Record" On Row Updating="Update Record" Cell Padding="4" Header Style-Horizontal Align="left" On Row Deleting="Delete Record" Row Style-Vertical Align="Top" Fore Color="#333333" Grid Lines="None" In the above code, I have kept Auto Generate Columns as false so that Grid View will not render all the fields of the data source automatically.

I have specified Data Key Names as Auto ID, the primary key of the database table.

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).

This will make sure that Bind Data() method will not fire when you are going to edit, update or delete the record.

Leave a Reply