Link to home
Start Free TrialLog in
Avatar of brgdotnet
brgdotnetFlag for United States of America

asked on

How to reference a column by name when iterating through a GridView ?

If I am iterating through rows in Grid View is their a way to reference the column by it's actual name?
I can do so in my RowDataBound event(See below). But I don't know how to do it when iterating through GridView.Rows.
Can someone show me how?

foreach(GridView row in grdView.Rows)
{

   string firstCol = row.Cells[0].Text; // How to reference by the column name instead of Zero?
   string SecondCol = row.Cells[1].Text; // How to reference by the column name instead of One?

}






protected void grdView_RowDataBound(Object sender, GridViewROwEventArgs e)
{

   var data = e.Row.DataItem as DataRowView;
   string custId = e.Row.Cells[data.Row.Table.Columns["CUST_ID"].Ordinal.Text;

}
ASKER CERTIFIED SOLUTION
Avatar of Prakash Samariya
Prakash Samariya
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial