Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to apply CSS to the internal elements of an ASP.NET CheckBoxList control

I need to manipulate the attributes of a label element inside an ASP.NET CheckBoxList control. Each checkbox label needs to have a different class. The best alternative I see is to apply the classes with jQuery after the fact. Does anyone know a better method?

I found this post marginally helpful, however, adding an attribute to the list item only wraps the input element and the label element in a span tag with the denoted attributes.

like image 541
smartcaveman Avatar asked Jan 19 '23 20:01

smartcaveman


1 Answers

Variation of Billy's second answer, but without server side code:

Assign the class to checkboxlist itself

<asp:CheckBoxList runat="server" id="MyCBL" CssClass="MyClass"></asp:CheckBoxList>

Any CSS you apply to the parent element (in this case the checkboxlist, which renders as a table) can be passed to its child elements:

<style>
    .MyClass label {color: Blue}
    .MyClass input[type='checkbox'] {background-color: Red}
</style>
like image 130
Barrie A Sargent Avatar answered Jan 30 '23 23:01

Barrie A Sargent