根据绑定的值的不同改变gridview里某一单元格的字体或背景颜色
第一种
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (Convert.ToInt32(e.Row.Cells[3].Text.Trim()) >5)
{
e.Row.BackColor = Color.Red;
}
}
}
第二种
<ItemTemplate>
<span style=' <%# "color:" + (Eval("yourField").ToString() == "1" ? "black" : (Eval ("yourField").ToString() == "2") ? "green" : "red" ) %> '> <%# Eval("xxx") %> </span>
</ItemTemplate>
本文转自kenty博客园博客,原文链接http://www.cnblogs.com/kentyshang/archive/2012/11/19/2778166.html如需转载请自行联系原作者
kenty