CheckBoxList items attributes : apply CssStyle

J

Jerome

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 - (e-mail address removed)
 
V

Victor Garcia Aprea [MVP]

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top