[ACCEPTED]-Set a CSS class on an ASP.NET RadioButtonList ListItem-listitem

Accepted answer
Score: 14

Yes, RadioButtonList renders horrible HTML.

Anyway, it's 3 still easy to get them from jQuery.

Try

$('span.myclass input:radio')

Above 2 will get all the radio buttons inside the 1 span with class 'myclass'.

Score: 9

An alternative you may want to try to do 7 is change your CSS class to accomindate 6 the Server Control Rendering.

So in your 5 CSS instead of the following:

.myClass { ... }

You Use this:

.myClass input { ... }

I 4 don't know if you can set the class attribute 3 (via class or CSSClass) in a declarative 2 manner; however, the above should give you 1 a work around.

Score: 3

untested

$('.myclass input:radio').each(function() {
        this.css({'style-name':'style-value'})
)};

once the list is rendered, you 2 can possibly manipulate the css client side 1 using the above statement.

Score: 2

Using .NET you could create an event handler 13 to the RowBinding event. This would allow 12 you to access the individual controls within 11 each item in the list. Once you pull the 10 RadioButton control, you could programaticaly 9 set it's CssClass to apply your class on 8 the RadioButton level.

You could also use 7 jquery to find the radio button controls 6 that have myClass applied, and then apply 5 another class to that.

Third, you could just 4 change the definition of MyClass to also 3 specify that it's only applied to input 2 elements under elements that have MyClass 1 applied.

Score: 1

the desigeek response is pretty good..

To 5 get this to work for radiobuttons I had 4 to do this on document.ready()

$('#<%=radRisksMarginTrading.ClientID  %>_0').addClass("validate[required]");
$('#<%=radRisksMarginTrading.ClientID  %>_1').addClass("validate[required]");

I'm sure there 3 is a much better way to do it by looping 2 but I need a quick fix for 5 radiobutton 1 lists..

More Related questions