gridview里面有几个字段,姓名,身份,病情等,如果病情为严重,我想把姓名这加上红色背景显示,不知道该怎么写?
我早上搜索了一下,看到一个可以把整行的背景都换,不知道换单元格的背景也这样?
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string bqred = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "病情 "));
if (bqred == "病危 ")
e.Row.BackColor = System.Drawing.Color.Brown;
}
}
------解决方案--------------------------------------------------------
Cells
领会原理的启示,然后自己勤查手册。
------解决方案--------------------------------------------------------
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType != DataControlRowType.DataRow) return;
e.Row.Cells[2].BackColor = System.Drawing.Color.BurlyWood;
}