Set a CSS class on an ASP.NET RadioButtonList ListItem

拟墨画扇 提交于 2019-11-29 05:28:51

Yes, RadioButtonList renders horrible HTML.

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

Try

$('span.myclass input:radio')

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

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

So in your CSS instead of the following:

.myClass { ... }

You Use this:

.myClass input { ... }

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

untested

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

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

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

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

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

the desigeek response is pretty good..

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

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!