ASP.NET WebForm中给GridView控件修改表格颜色

前台代码就不放了,直接拉取控件没有做任何操作,想看的参考上一篇文章,直接放后台代码:

protected void GridView1_RowDataBound1(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {

                if (Convert.ToInt32(e.Row.Cells[1].Text)>80)
                {
                    e.Row.Cells[1].BackColor = System.Drawing.Color.Blue;
                }
                else if (Convert.ToInt32(e.Row.Cells[1].Text) > 60)
                {
                    e.Row.Cells[1].BackColor = System.Drawing.Color.Yellow;
                }
                else if (Convert.ToInt32(e.Row.Cells[1].Text) > 40)
                {
                    e.Row.Cells[1].BackColor = System.Drawing.Color.Red;
                }
                else if (Convert.ToInt32(e.Row.Cells[1].Text) > 20)
                {
                    e.Row.Cells[1].BackColor = System.Drawing.Color.Green;
                }
                else if (Convert.ToInt32(e.Row.Cells[1].Text) >0 )
                {
                    e.Row.Cells[1].BackColor = System.Drawing.Color.Pink;
                }
            }
        }

Color哪里报错的话记得引用一个using System.Drawing;

猜你喜欢

转载自blog.csdn.net/qq_42450386/article/details/85161097