开发者

Change css class depending on label's text

I have asp:Table with number of asp:Label inside asp:FormView, it represents short stats info.

I need to set Label.CssClass to "red" if it's text isn't "0".

Curr开发者_JAVA百科ently I do this on FormView.DataBound event. But think that it's better to use JavaScript and probably jQuery. How can I do that?

Sorry for dummy question - I'm new to jQuery. Thanks!


You can do this using jQuery (you can also give the Table or FormView a class, probably easier in aps.net instead of the ID like I have below):

$("#formViewOrTableID span").filter(function() {
  return $(this).text() !== "0";
}).addClass("redClass");

If you give the labels a class you want affected, say set all the Labels you want included to CssClass="styleMe", you could change $("#formViewID span") to
$("#formViewID span.styleMe") to be more specific.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜