Gridview onrowupdating event

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.

In this method, I am specifying the Edit Index property of the Grid View to -1.

As there is no row at -1 position so Grid View will be shown in normal mode.

You can notice that I have kept Required Field Validator too inside the Edit Item Template as I want the textbox to be validated for empty data.

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.

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.

gridview onrowupdating event-12gridview onrowupdating event-59gridview onrowupdating event-16

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

Connect me on | https://twitter.com/sheonarayan | Hello....

In the template field I will Place a label or some controls, So that it’s very easy to access those controls in the code behind by using Find Control method. Item Template is the content to display for the items in the Template Field.

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.

Leave a Reply