Solved

Set color and font size in code-behind?

Posted on 2004-11-02
3,709 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
Question by:tbaseflug
    13 Comments
     
    LVL 28

    Expert Comment

    by:mmarinov
    Hi tbaseflug,

    you can use

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

    Regards!
    B..M
    0
     

    Author Comment

    by:tbaseflug
    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
    tbaseflug,

    in this case you cah use

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

    B..M
    0
     

    Author Comment

    by:tbaseflug
    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:
    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
    Arvaris -

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

    Expert Comment

    by:mmarinov
    Arvaris,

    great!

    B..M
    0
     
    LVL 2

    Expert Comment

    by:Arvaris
    I'm glad I could help
    0
     

    Author Comment

    by:tbaseflug
    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
    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
    Arvaris -

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

    Expert Comment

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

    Expert Comment

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    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…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    933 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

    17 Experts available now in Live!

    Get 1:1 Help Now