Set color and font size in code-behind?

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?
tbaseflugAsked:
Who is Participating?
 
ArvarisConnect With a Mentor Commented:
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
 
mmarinovCommented:
Hi tbaseflug,

you can use

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

Regards!
B..M
0
 
tbaseflugAuthor Commented:
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
mmarinovCommented:
tbaseflug,

in this case you cah use

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

B..M
0
 
tbaseflugAuthor Commented:
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
 
tbaseflugAuthor Commented:
Arvaris -

Perfect - just what I was looking for - Thanks!
0
 
mmarinovCommented:
Arvaris,

great!

B..M
0
 
ArvarisCommented:
I'm glad I could help
0
 
tbaseflugAuthor Commented:
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
 
ArvarisCommented:
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
 
tbaseflugAuthor Commented:
Arvaris -

Thanks for the great / prompt response - your assistance was and is greatly appreciated!
0
 
ArvarisCommented:
no problem, i'm just happy that I could help.
0
 
ArvarisCommented:
Also, if you could please accept my answer...that would be great.  Thanks and good luck.
0
All Courses

From novice to tech pro — start learning today.