brgdotnet
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(Objec t sender, GridViewROwEventArgs e)
{
var data = e.Row.DataItem as DataRowView;
string custId = e.Row.Cells[data.Row.Table .Columns[" CUST_ID"]. Ordinal.Te xt;
}
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(Objec
{
var data = e.Row.DataItem as DataRowView;
string custId = e.Row.Cells[data.Row.Table
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.