Sunday, August 17, 2008

How to get invisible column values in gridview

The requiremnet is to get the values of the hidden fields values in the gridview

Define the Datakey array in the gridview as follows:

DataKeyNames="EmpID,EmpName,Grade,Servicedate,PositionDescription,DeptFullDesc,EmpType"

Now how to access the DataKey Array for the selected row in code beind. The blow mentioned code populate the label controls.

DataKey dRow = grdReportingEmployee.DataKeys[grdReportingEmployee.SelectedRow.DataItemIndex];

lblEmployeeNumber.Text = dRow[0].ToString();
lblEmployeeName.Text = dRow[1].ToString();
lblGrade.Text = dRow[2].ToString();
lblHireDate.Text = dRow[3].ToString();
lblJobTitle.Text = dRow[4].ToString();
lblDepartment.Text = dRow[5].ToString();