根据文本更改行颜色

时间:2012-05-28 08:06:31

标签: c# asp.net

嘿伙计们我坚持这个。只是尝试根据单元格文本值更改行颜色。这就是我现在所拥有的

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
                    string value = Convert.ToString(DataBinder.Eval(e.Row.DataItem,"Field1"));

                    if (value == "Complete")
                    {
                        e.Row.BackColor = System.Drawing.Color.FromName("#c6efce");
                    }
                }
            }
        }
    }

1 个答案:

答案 0 :(得分:0)

Color.FromName方法需要一个颜色名称,并且您传递的是十六进制颜色值,请将其替换为:

using System.Drawing;
...  
e.Row.BackColor = Color.FromArgb(Convert.ToInt32("c6efce", 16));

OR

e.Row.BackColor = ColorTranslator.FromHtml("#c6efce");