根据文本更改行颜色 [英] change row colour based on text

查看:80
本文介绍了根据文本更改行颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我坚持了这一点.只是尝试根据单元格文本值更改行颜色.这就是我目前所拥有的

hey guys im stuck on this. Just trying to change the row colour based on cell text value. this is what i have at the moment

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");
                    }
                }
            }
        }
    }

推荐答案

Color.FromName 方法需要颜色名称,并且您要传递十六进制颜色值,请用以下颜色替换:

Color.FromName method requires a color name and you are passing hexadecimal color value, replace it with this:

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

OR

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

这篇关于根据文本更改行颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆