Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Set color and font size in code-behind?

Posted on 2004-11-02
13
Medium Priority
?
3,720 Views
Last Modified: 2013-12-03
Need to know how to se the color value in a code-behind page to a hex color such as #990000?  

Also, need to know how to set the font size?
0
Comment
Question by:tbaseflug
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 3
13 Comments
 
LVL 28

Expert Comment

by:mmarinov
ID: 12473104
Hi tbaseflug,

you can use

txtID.Attributes.Add("style", "font-size:10px; color: #990000" )

Regards!
B..M
0
 

Author Comment

by:tbaseflug
ID: 12473119
Actually, am trying to programtically set teh header color and font size for a datagrid in the codebehind - would that be applicable?  Do I have to use System.Drawing.Color, etc.?
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 12473162
tbaseflug,

in this case you cah use

DataGrid.HeaderStyle.CssClass and add the CSS style that contains the appropriate values

B..M
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:tbaseflug
ID: 12473264
mmarinov -

Thanks - That would normally work great but am actually rendering the control (datagrid) as the body of an email and as such the CSS does not ship with it - would like to set the font size and color with the code-behind to force it
0
 
LVL 2

Accepted Solution

by:
Arvaris earned 200 total points
ID: 12473348
Just do DataGrid.HeaderStyle.ForeColor = Color.FromArgb(153, 0, 0) // The RGB equivalent of #990000
and for font size
DataGrid.HeaderStyle.Font.Size = FontUnit.Parse("12px") // would set the font-size to 12px

Also, if you don't know how to convert from Hex color to RGB color, hex color is in the format RRGGBB and you could take each value into a calculator, set the base to Hex and put in 99, then switch to decimal and it should give 153.  Or put it into a program like adobe photoshop.

Hope this helps!
0
 

Author Comment

by:tbaseflug
ID: 12473355
Arvaris -

Perfect - just what I was looking for - Thanks!
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 12473389
Arvaris,

great!

B..M
0
 
LVL 2

Expert Comment

by:Arvaris
ID: 12473407
I'm glad I could help
0
 

Author Comment

by:tbaseflug
ID: 12473460
Arvaris -

One last quick one - any idea why, on the page it looks great, but when I render the control in te body of my html email the font size looks tiny - trying to set it to 10px?
0
 
LVL 2

Expert Comment

by:Arvaris
ID: 12473549
Well, 10px itself is pretty tiny...I usually go no less than 11px...and 12px is the default for most things.  But there are some rendering issues with HTML emails.  First off, what are you using to view the email...Yahoo generally is pretty good at displaying HTML emails (as long as its in IE) and Microsoft Outlook 2000 and up generally does a good job (though it can screw up embedded tables pretty good).  The problem is, a datagrid can sometimes render itself a little funky (adding non-common tags that confuse a lot of non-microsoft related email software).  The best thing might actually to be to use a DataRepeater control and build out the table yourself, however if that isn't an option...just make the font size 12px or so...maybe 14px if needed.
0
 

Author Comment

by:tbaseflug
ID: 12473572
Arvaris -

Thanks for the great / prompt response - your assistance was and is greatly appreciated!
0
 
LVL 2

Expert Comment

by:Arvaris
ID: 12473618
no problem, i'm just happy that I could help.
0
 
LVL 2

Expert Comment

by:Arvaris
ID: 12474144
Also, if you could please accept my answer...that would be great.  Thanks and good luck.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

618 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