Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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");
                    }
                }
            }
        }
    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
200 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...