P
Paul
Hello All,
I am trying to use the following RowCreated Event Handler to make the
BackColor of a cell different if it has a particular value.
protected void GridView1_RowCreated(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
object cellValue = DataBinder.Eval(e.Row.DataItem,
"Primary Diagnosis");
if(cellValue != null)
{
if (cellValue.Equals("Unknown or Service Recipient
Declined"))
{
e.Row.Cells[1].BackColor = Color.Yellow;
}
}
}
}
The page works as expected the first time it is loaded. But if it is a
PostBack cellValue is null, so the code to color the cells BackColor
does not run. If I take out condition "if(cellValue != null) I get an
error message. How can I use the RowCreated Event handler to control
the BackColor of cells even when it is a PostBack.
Help is always appreciated. Thanks,
Paul
I am trying to use the following RowCreated Event Handler to make the
BackColor of a cell different if it has a particular value.
protected void GridView1_RowCreated(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
object cellValue = DataBinder.Eval(e.Row.DataItem,
"Primary Diagnosis");
if(cellValue != null)
{
if (cellValue.Equals("Unknown or Service Recipient
Declined"))
{
e.Row.Cells[1].BackColor = Color.Yellow;
}
}
}
}
The page works as expected the first time it is loaded. But if it is a
PostBack cellValue is null, so the code to color the cells BackColor
does not run. If I take out condition "if(cellValue != null) I get an
error message. How can I use the RowCreated Event handler to control
the BackColor of cells even when it is a PostBack.
Help is always appreciated. Thanks,
Paul