D
dev648237923
I have a gridview and I call RowDataBound to change the backcolor of a cell
in the Status colomn based on the contents of a field.
I do that below by specifying the column's index by number (4 on my grid) --
but I'd like to specify it by using the column's name ("Status" in my grid).
How can I get the cell index by specifying a bound column's name?
Thank you
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs
e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//4 is the column that has Status -- I need a better way to choose this
column
e.Row.Cells[4].BackColor = System.Drawing.Color.FromName(
DataBinder.Eval(e.Row.DataItem, "StatusColor").ToString());
}
}
in the Status colomn based on the contents of a field.
I do that below by specifying the column's index by number (4 on my grid) --
but I'd like to specify it by using the column's name ("Status" in my grid).
How can I get the cell index by specifying a bound column's name?
Thank you
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs
e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//4 is the column that has Status -- I need a better way to choose this
column
e.Row.Cells[4].BackColor = System.Drawing.Color.FromName(
DataBinder.Eval(e.Row.DataItem, "StatusColor").ToString());
}
}