.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Home >> Code Snippets >> ASP.NET Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

How to use DataKeyNames property to access value that uniquely identify each row in grid view

Posted By:shankey       Posted Date: July 26, 2011    Points: 40    Category: ASP.NET Controls    URL: http://www.dotnetspark.com  

How to use DataKeyNames property of Gridview to access value that uniquely identify each row in grid

Hi all,

This article will help you to understand what is the use of datakeynames property of grid view.

In our scenario a row in a grid is uniquely identify by a combination of classid and studentid.

To understand this first declare data key name property with these two key name. As shown below:

Now on row command we will get the datakeynames value to identify the row uniquely that was clicked or which is the source of the rowcommand event.

To get the datakeyname value please try to understand following line:
string classIdvalue=gridView1.DataKeys[RowIndex].Values["classId"].ToString();
string studentIdvalue=gridView1.DataKeys[RowIndex].Values["studentId"].ToString();  
now you can make updation to this student based on classid and studentid combination.


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend