Get datakey value gridview rowupdating event

24-Jul-2017 18:49

Re-obtaining the List of objects via the utility method along with the index obtained from the event arg parameter is not an option because the List of objects may have changed. I have a Grid View with an associated Data Key, which is the item ID.We can achieve the same functionality using Datakeys. 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. ), and I'm not too confident about the Naming Container bit. Command Source; Grid View Row gvr = (Grid View Row)lb. aspdotnet-suresh offers C#articles and tutorials,csharp dot net,articles and tutorials, VB.Actually, the only way I found to get something from the Command Argument parameter is to set it in the aspx page like this : In this exemple, DATAFIELD1 and DATAFIELD2 are data column.With that solution, my problem is that I dont always have the key display in the data column.

This seems to work, but I don't like the cast to Link Button (what if some other command is firing the event? I'm also aware that it's possible to use a hidden field for the ID, but I consider that a hack that I don't want to use.event is raised when a row's Update button is clicked, but after the Grid View control updates the row.