Help with setting background colors or even and odd rows of a checkbox list control

vcharles
vcharles used Ask the Experts™
on
Hi,

How do you set background colors or even and odd rows of a checkbox list web control?

Victor
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Ramkisan JagtapLead Developer

Commented:
Systems Development / Support Specialist
Commented:
     ListItem[] items = new ListItem[10];
        for (int i = 0; i < 10; i++)
        {
            items[i] = new ListItem();
            items[i].Text = "items" + i;
            items[i].Value = "items" + i;
            items[i].Attributes.Add("items" + i,  "items" + i);
            if (i % 2 == 0)

                items[i].Attributes["style"] = " background-color:#00AFF0; ";
            else
                items[i].Attributes["style"] = " background-color:#c7c7c7; ";
        }
        CheckBoxList cb = new CheckBoxList();
        cb.Items.AddRange(items);
        form1.Controls.Add(cb);

Open in new window

Author

Commented:
Thanks, does this apply to all checkbox  list controls on my form?  where in my form do I include the code in the previous post?

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial