>我已经在行数据绑定中给出了条件,但它在 lblstatus 中给了我 " 值..... 我想根据下面提到的给定条件更改单元格的背景颜色是代码和设计我在网格中的值填充在项目模板和项目模板中的标签中
protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
String lblstatus = "";
if (e.Row.RowType == DataControlRowType.DataRow)
{
foreach (GridViewRow row in grv_taskfilter.Rows)
{
for (int i = 0; i < grv_taskfilter.Columns.Count; i++)
{
//String header = GridView2.Columns[i].HeaderText;
lblstatus = row.Cells[i].Text.ToString();
if (lblstatus == "Not yet started")
{
e.Row.BackColor = System.Drawing.Color.Gray;
}
if (lblstatus == "In progress")
{
e.Row.BackColor = System.Drawing.Color.Orange;
}
if (lblstatus == "Alert")
{
e.Row.BackColor = System.Drawing.Color.Yellow;
}
if (lblstatus == "Missed deadline")
{
e.Row.BackColor = System.Drawing.Color.Red;
}
if (lblstatus == "Not Applicable")
{
e.Row.BackColor = System.Drawing.Color.BlueViolet;
}
}
}
}
protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
String lblstatus = "";
if (e.Row.RowType == DataControlRowType.DataRow)
{
这个foreach不需要你在行数据绑定事件意味着每次新的行绑定到这里
// foreach (GridViewRow row in grv_taskfilter.Rows)
// {
for (int i = 0; i <e.row.cells.Count; i++)
{
lblstatus = e.row.Cells[i].Text.ToString();//use e.rows.cell[]
if (lblstatus == "Not yet started")
{
e.Row.BackColor = System.Drawing.Color.Gray;
}
if (lblstatus == "In progress")
{
e.Row.BackColor = System.Drawing.Color.Orange;
}
if (lblstatus == "Alert")
{
e.Row.BackColor = System.Drawing.Color.Yellow;
}
if (lblstatus == "Missed deadline")
{
e.Row.BackColor = System.Drawing.Color.Red;
}
if (lblstatus == "Not Applicable")
{
e.Row.BackColor = System.Drawing.Color.BlueViolet;
}
// }
}
}