New value in gridview rowupdating event

Rated 3.99/5 based on 969 customer reviews

In my case this was happening because I was binding to a List of custom objects.Note A common mistake that a lot of people do is that they perform a databind each and every-time the Page_Load method is called. When I click on the edit button the update and cancel button appear.Upon modifying the values in textbox which come from Edit Item Template , the new values dont show in the event handler rowupdating(), instead I get the values which appear when the page was rendered.For this situation, many developers use invisible columns (Hidden columns) in the gridview to identify that row. We can achieve the same functionality using Datakeys. As the values are inserted into an Ordered Dictionary - you can use the field names to access the changed data 2.

Obviously the simplest method is to use Data Key Names on the Grid View and then you should have the data in your Grid View Update Event Args as part of e. (In the following example, I cast to a Check Box as I know I have a checkbox at the col Index You Are Interested In - you should cast to whatever control you have in that column).

A datakey represents the primary key field or field of a record that can uniquely identify it in a data-bound control. Row Index represents the index of the particular row.

Many a times in our applications we use primary keys to get control of the particular record in the gridview.

In this example, I am going to retrieve values from categories table of Northwind database. Drag a Grid View into the Web Form and assign Data Key Names property with the primary key column i.e. In the gdview_Row Editing and gdview_Row Deleting event, we have used the below code to retrieve categoryid from datakey of Grid View, int catid = int.

In this article we create a Gridview from database and add some additional operations such a add, edit and delete data in the Grid View control.

Leave a Reply