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. 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. Now you can ask questions directly to me on my new site ASPForums. Buttons within a Grid View control can also invoke some of the built-in functionality of the control.To perform one of these operations, set the Command Name property of a button to one of the values in the following table. Sets the Command Argument property of the button to "First", "Last", "Next", "Prev", or a page number to specify the type of paging operation to perform.This enables you to provide an event-handling method that performs a custom routine, such as canceling the update operation, whenever this event occurs.A Grid View Update Event Args object is passed to the event-handling method, which enables you to determine the index of the current row and to indicate that the update operation should be canceled.
event is raised when a row's Update button is clicked, but before the Grid View control updates the row.For example you could have the following code:to store the information. Finally the code is bound to the When the user selects a record from the grid, the selected row index will be passed through as the Command Argument.Run the project and place a breakpoint on the code above. The program will stop on the breakpoint and you will be able to see the selected row index being passed through.event is raised when a button is clicked in the Grid View control.This enables you to provide an event-handling method that performs a custom routine whenever this event occurs. I will click on the EDIT link in one of the grid view row. I will update the values and click update link in edit mode and edit mode closes. At this point I need to capture the datakey of the updated row into some variable Can someone please help me out with this? Open Visual Studio 2008 and create a new Web Application. 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. I'm using a sqldatasource control to populate the grid and want to write the update code in the Row Updating event. I can get the value of the first field using " Select Command="SELECT @Week Ending Week Ending , Project , Project ID , Category , Category ID ,isnull(, 0) Sun ,isnull(, 0) Mon ,isnull(, 0) Tue ,isnull(, 0) Wed ,isnull(, 0) Thu ,isnull(, 0) Fri ,isnull(, 0) Sat from (select P. The key fields are defined in the Data Key Names property of a Grid View control.