Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Applying Styles To ListItems in CheckBoxList

How can styles be applied to CheckBoxList ListItems. Unlike other controls, such as the Repeater where you can specify <ItemStyle>, you can't seem to specify a style for each individual control.

Is there some sort of work around?

like image 837
Andrew Burgess Avatar asked Sep 19 '08 18:09

Andrew Burgess


2 Answers

You can add Attributes to ListItems programmatically as follows.

Say you've got a CheckBoxList and you are adding ListItems. You can add Attributes along the way.

ListItem li = new ListItem("Richard Byrd", "11"); li.Selected = false; li.Attributes.Add("Style", "color: red;"); CheckBoxList1.Items.Add(li); 

This will make the color of the listitem text red. Experiment and have fun.

like image 139
Cyberherbalist Avatar answered Oct 05 '22 05:10

Cyberherbalist


It seems the best way to do this is to create a new CssClass. ASP.NET translates CheckBoxList into a table structure.

Using something like

Style.css

.chkboxlist td  {     font-size:x-large; } 

Page.aspx

<asp:CheckBoxList ID="chkboxlist1" runat="server" CssClass="chkboxlist" /> 

will do the trick

like image 24
Andrew Burgess Avatar answered Oct 05 '22 05:10

Andrew Burgess