【发布时间】:2018-07-07 16:34:20
【问题描述】:
我有这段代码用于在 Gridview 的某些单元格中设置背景颜色,但我无法让它在第一行工作。
protected void GrdTask_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
foreach(GridViewRow row in GrdTask.Rows)
{
if (Convert.ToInt32(e.Row.Cells[1].Text) == 0)
{
e.Row.Cells[1].Attributes["Style"] = "background-color: #f20713";
}
if (Convert.ToInt32(e.Row.Cells[1].Text) <= -3)
{
e.Row.Cells[1].Attributes["Style"] = "background-color: #f4d942";
}
if (Convert.ToInt32(e.Row.Cells[1].Text) <= -5)
{
e.Row.Cells[1].Attributes["Style"] = "background-color: #28b779";
}
}
}
对于所有其余的行,它都可以正常工作。我做错了什么?
【问题讨论】:
标签: asp.net