DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Use Datakey Names

01.31.2012
| 2402 views |
  • submit to reddit
        Set following attribute of your grid view i.e. aspx 

DataKeyNames="employeeId,departmentId"

Mostly following code in written when you have to iterate gridview on server side i.e. aspx.cs
string employeeId=gridView1.DataKeys[RowIndex].Values["employeeId"].ToString();
string departmentId=gridView1.DataKeys[RowIndex].Values["departmentId"].ToString();