AspdotnetCodes.com
US and UK Data Centers – DiscountASP.NET
 
Articles Subscribe for our Articles Updates
Books
Resources
Downloads
Free Tech Magazines
Archives
Softwares
Newsletter
Suggest Us
Link to Us
 How to Use More than One DataKeyNames in Asp.Net 2.0 GridView
Posted by Moderator1 on  2/15/2008 8:01:29 PM 710 Views
 
DataKeyNames is a property to define Read-only primary key like fields in a GridView control. We can also add some more fields to this property separated by commas.

For example, if 'CusCode' is the primary key and you want 'CusType' as a readonly field, you can assign the GridView control's DataKeyNames property as CusCode,CusType.

To retreive the value from the GridView control in RowDataBound event or any other event of the GridView control, use the below syntax.
To take Field 1, use GridView1.DataKeys[e.Row.RowIndex][0].ToString()
To take Field 2, use GridView1.DataKeys[e.Row.RowIndex][1].ToString()
To take Field n, use GridView1.DataKeys[e.Row.RowIndex][n-1].ToString()

Happy Codings..


Post New Tips/Tricks View all Tips/Tricks

Sponsored by