7

I have a RadioButtonList that is being rendered as an Unordered list. My issue is I am adding a class to the ListItem and it is creating a span in which the class is being placed. Is there a way I can have the class placed on the LI tag instead? How can I go about it?

var cblAttributes = new RadioButtonList();
cblAttributes.ID = controlId;
cblAttributes.RepeatLayout = RepeatLayout.UnorderedList;

var pvaValueItem = new ListItem(Server.HtmlEncode(frame.Name), frame.FrameId.ToString());
pvaValueItem.Attributes.Add("class", "frame-item");
cblAttributes.Items.Add(pvaValueItem);

Output is below:

<li>
    <span class="frame-item">
    <input id="INPUTID" type="radio" name="INPUTNAME" value="1">
    <label for="INPUTID">TEXT</label>
    </span>
</li>
brenjt
  • 15,997
  • 13
  • 77
  • 118
  • Do you want to apply this class for all list items in the list? – Yuriy Rozhovetskiy Jul 08 '11 at 14:58
  • 2
    if anything you could give the `ul` an id and select it in css like `#ulID li { }`. Not really an answer to your question but perhaps a viable workaround. – Bazzz Jul 08 '11 at 15:00
  • @OneHalfTrackMindMan Yes the class would be applied to all. @Bazzz it would be a simple workaround but I am now curious as to how it can be done if it can. – brenjt Jul 08 '11 at 15:01
  • @brenjt: couldn't you add the class to the RadioButtonList's [CssClass-Property](http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.webcontrol.cssclass.aspx) then? Btw, it's an duplicate: http://stackoverflow.com/questions/1070960/set-a-css-class-on-an-asp-net-radiobuttonlist-listitem – Tim Schmelter Jul 08 '11 at 15:06
  • then create new css class like ul.frame-items li { frame-item class definition here } and apply frame-items class on the RadioButtonList via the CssClass property – Yuriy Rozhovetskiy Jul 08 '11 at 15:08
  • @Tim Schmelter It's actually not a duplicate. His question is slightly different. – brenjt Jul 08 '11 at 15:11
  • @brenjt: yes, sorry, i've seen it myself a few seconds after i've commented. It's only similar. – Tim Schmelter Jul 08 '11 at 15:12

1 Answers1

2

You can create new css class like ul.frame-items li { frame-item class definition here } and apply frame-items class on the RadioButtonList via the CssClass property

Yuriy Rozhovetskiy
  • 22,270
  • 4
  • 37
  • 68
  • Great work around. Simple and I had already added this to my css. I want to know out of curiosity if what I asked above can be accomplished. – brenjt Jul 08 '11 at 15:15
  • I'm not sure but suppose that this can be achieved by implementing own RadioButtonList class inherited from the existing one or with control adapter for the RadioButtonList control. – Yuriy Rozhovetskiy Jul 08 '11 at 15:23
  • Very true. I just found this http://cssfriendly.codeplex.com/SourceControl/changeset/view/73982#9854 – brenjt Jul 08 '11 at 15:28