Solved

c# Net Set Label Colour

Posted on 2011-03-08
4
575 Views
Last Modified: 2012-05-11
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;

0
Comment
Question by:LBGUC04
  • 2
4 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 35068783
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);  

0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 35068788
Try:
(e.Row.FindControl("lblGroupName") as Label).BackColor = System.Color.FromName("FF0000");

Open in new window

0
 
LVL 10

Expert Comment

by:Asim Nazir
ID: 35068794
0
 
LVL 10

Expert Comment

by:Asim Nazir
ID: 35068822
You can also use:

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

Open in new window

0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now