Link to home
Start Free TrialLog in
Avatar of tbaseflug
tbaseflugFlag for United States of America

asked on

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?
Avatar of mmarinov
mmarinov

Hi tbaseflug,

you can use

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

Regards!
B..M
Avatar of tbaseflug

ASKER

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.?
tbaseflug,

in this case you cah use

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

B..M
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
ASKER CERTIFIED SOLUTION
Avatar of Arvaris
Arvaris
Flag of United States of America 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
Arvaris -

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

great!

B..M
I'm glad I could help
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?
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.
Arvaris -

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