Change GridView row color based on condition

前端 未结 7 1009
时光说笑
时光说笑 2020-12-01 14:04

I want to change a particular row color of gridview based on some condition, I am using ASP.NET with c#. Thank you.

7条回答
  •  粉色の甜心
    2020-12-01 14:23

    \\loop throgh all rows of the grid view  
    
    if (GridView1.Rows[i - 1].Cells[4].Text.ToString() == "value1")
    {
       GridView1.Rows[i - 1].ForeColor = Color.Black;
    }
    else if (GridView1.Rows[i - 1].Cells[4].Text.ToString() == "value2")
    {
       GridView1.Rows[i - 1].ForeColor = Color.Blue;
    }
    else if (GridView1.Rows[i - 1].Cells[4].Text.ToString() == "value3")
    {
       GridView1.Rows[i - 1].ForeColor = Color.Red;
    }
    else if (GridView1.Rows[i - 1].Cells[4].Text.ToString() == "value4")
    {
       GridView1.Rows[i - 1].ForeColor = Color.Green;
    }
    

提交回复
热议问题