Link to home
Start Free TrialLog in
Avatar of LBGUC04
LBGUC04

asked on

c# Net Set Label Colour

I have the below i can use to set the fore/back colour of a label but i want to be able to set it to a hex value, how can i do this ?

(e.Row.FindControl("lblGroupName") as Label).BackColor = System.Drawing.Color.Red;

Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

Can you try the following:

(e.Row.FindControl("lblGroupName") as Label).BackColor  = Color.FromArgb(Int32.Parse(child.InnerText.Replace("#",""),System.Globalization.NumberStyles.HexNumber));

OR

string hex = "0xFF0000";  
int red   = HexToInt(hex.SubString(2, 2));  
int green = HexToInt(hex.SubString(4, 2));  
int blue  = HexToInt(hex.SubString(6, 2));  
(e.Row.FindControl("lblGroupName") as Label).BackColor  = Color.FromArgb(red, green, blue);  

ASKER CERTIFIED SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can also use:

 
Color.FromArgb(Int32.Parse(child.InnerText.Replace("#",""),System.Globalization.NumberStyles.HexNumber));

Open in new window