Applying Styles To ListItems in CheckBoxList

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.

Leave a Comment