CheckBoxList items attributes : apply CssStyle

Discussion in 'ASP .Net Web Controls' started by Jerome, Jul 15, 2003.

  1. Jerome

    Jerome Guest

    Hello,

    I populate dynamically a CheckBoxList then try to apply a specific
    font/size/color to the items of that CheckBoxList.
    My code compiles but it seems I cannot reach the items...
    (following pieces of code in C#)

    ********************************************************

    //I populate my CheckBoxList called cblSpec
    cblSpec.DataSource = specColl;
    cblSpec.DataValueField = "Id";
    cblSpec.DataTextField = "Libelle";
    cblSpec.DataBind();

    //then I try to apply a specific font, color, whatever style
    //to each item in that CheckBoxList
    foreach (ListItem item in cblSpec.Items)
    {
    item.Attributes.CssStyle.Add("font","10pt verdana");
    item.Attributes.CssStyle.Add("color","red");
    }

    **************************************************
    I cannot find any verdana keyword in the html source of the page once
    I've launched it. The style (font/color) simply disappears into thin
    air and is never rendered.

    All I was able to do is apply a style to the CheckBoxList itself but
    only the color would be applied downward to the items, not the font :(

    ****************************************************

    System.Web.UI.AttributeCollection myAttrib = cblSpec.Attributes;
    myAttrib.CssStyle.Add("color","blue"); //works on the items
    myAttrib.CssStyle.Add("font-weight","bold"); //works on the items
    myAttrib.CssStyle.Add("font","10pt times"); //does NOT reach the items
    :(

    ****************************************************

    I cant find any exemple anywhere on the web or MS help.
    Seems like it's impossible but I might be wrong so if anyone ever
    managed to do such a thing, please copy/paste some code.
    thx,

    Jerome -
     
    Jerome, Jul 15, 2003
    #1
    1. Advertising

  2. Hi Jerome,

    You've hit a well-known bug. Do a quick search on http://groups.google.com
    to find tons of post about it. I've posted about it more than a year ago
    along with some code to work-around it.

    --
    Victor Garcia Aprea
    Microsoft MVP | ASP.NET
    Looking for insights on ASP.NET? Read my blog:
    http://obies.com/vga/blog.aspx
    To contact me remove 'NOSPAM'. Please post all questions to the newsgroup
    and not by private mail.

    "Jerome" <> wrote in message
    news:...
    > Hello,
    >
    > I populate dynamically a CheckBoxList then try to apply a specific
    > font/size/color to the items of that CheckBoxList.
    > My code compiles but it seems I cannot reach the items...
    > (following pieces of code in C#)
    >
    > ********************************************************
    >
    > //I populate my CheckBoxList called cblSpec
    > cblSpec.DataSource = specColl;
    > cblSpec.DataValueField = "Id";
    > cblSpec.DataTextField = "Libelle";
    > cblSpec.DataBind();
    >
    > //then I try to apply a specific font, color, whatever style
    > //to each item in that CheckBoxList
    > foreach (ListItem item in cblSpec.Items)
    > {
    > item.Attributes.CssStyle.Add("font","10pt verdana");
    > item.Attributes.CssStyle.Add("color","red");
    > }
    >
    > **************************************************
    > I cannot find any verdana keyword in the html source of the page once
    > I've launched it. The style (font/color) simply disappears into thin
    > air and is never rendered.
    >
    > All I was able to do is apply a style to the CheckBoxList itself but
    > only the color would be applied downward to the items, not the font :(
    >
    > ****************************************************
    >
    > System.Web.UI.AttributeCollection myAttrib = cblSpec.Attributes;
    > myAttrib.CssStyle.Add("color","blue"); //works on the items
    > myAttrib.CssStyle.Add("font-weight","bold"); //works on the items
    > myAttrib.CssStyle.Add("font","10pt times"); //does NOT reach the items
    > :(
    >
    > ****************************************************
    >
    > I cant find any exemple anywhere on the web or MS help.
    > Seems like it's impossible but I might be wrong so if anyone ever
    > managed to do such a thing, please copy/paste some code.
    > thx,
    >
    > Jerome -
     
    Victor Garcia Aprea [MVP], Jul 16, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JD
    Replies:
    5
    Views:
    11,721
    NetArchitect
    Aug 8, 2007
  2. Patrick.O.Ige
    Replies:
    5
    Views:
    19,171
    Patrick.O.Ige
    Jun 19, 2005
  3. Stefan Siegl
    Replies:
    1
    Views:
    976
    Marrow
    Jul 18, 2003
  4. Bart Van Hemelen
    Replies:
    2
    Views:
    4,693
    Bart Van Hemelen
    Sep 4, 2006
  5. Replies:
    1
    Views:
    109
    JDP@Work
    Jun 22, 2005
Loading...

Share This Page