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.
Instead of looping you can use a linq query on your datasource like if your datasource is a list, obj = l Objs.
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.
So I wonder how to get the datakey for each row in a grid view.