We have a list that is getting generated server side, then using <asp:RadioButtonList... to display it.
How ever, how would we add some HTML after one of the items?
The idea is that if one of them is generated, there are some 'sub' radio buttons that get generated.
Thanks
ASP.NET:
private void PopulateFollowUpRadioButtons(Order order)
{
//Based on the options selected while creating the order template populate the radio button list.
if (order.OrderTemplate.fur01Visible)
FolloupRadioButtonList.Items.Add(new ListItem(order.OrderTemplate.fur01Label, "1"));
if (order.OrderTemplate.fur02Visible)
FolloupRadioButtonList.Items.Add(new ListItem(order.OrderTemplate.fur02Label, "2"));
if (order.OrderTemplate.fur03Visible)
FolloupRadioButtonList.Items.Add(new ListItem(order.OrderTemplate.fur03Label, "3"));
//If follow up option is already selected then select the option in the Follow Up Radio button control
if (order.FollowUpRoleId != null)
FolloupRadioButtonList.SelectedValue = order.FollowUpRoleId.Value.ToString();
}
<asp:RadioButtonList ID="FolloupRadioButtonList" CssClass="black" ForeColor="Black" runat="server"></asp:RadioButtonList>
Create your own custom radiobuttonlistcontrol:
Namespace Controls
Public Class MyRadioButtonList
Inherits RadioButtonList
Protected Overrides Sub RenderItem(itemType As System.Web.UI.WebControls.ListItemType, repeatIndex As Integer, repeatInfo As System.Web.UI.WebControls.RepeatInfo, writer As System.Web.UI.HtmlTextWriter)
writer.Write("<div>Extra content</div>")
MyBase.RenderItem(itemType, repeatIndex, repeatInfo, writer)
End Sub
End Class
End Namespace
And use it as so.
First register the control to a page, or a user control:
<%@ Register Assembly="(projectnamespace)" Namespace="(projectnamespace).Controls" TagPrefix="cc1" %>
And then use the control:
<cc1:MyRadioButtonList ID="rdolist" runat="server" />
It's a basic radiobuttonlistcontrol in the server side, so just use it as you do now.
Technically you can assign your HTML directly to ListItem text e.g. this code
ListItem li = new ListItem("aaaaa", "aaaaa");
FolloupRadioButtonList.Items.Add(li);
li = new ListItem("bbbbb", "bbbbbbb");
FolloupRadioButtonList.Items.Add(li);
li.Text += @"<table style='padding-left:50px'>
<tr>
<td><input id='ChildList_0' type='radio' name='ChildList' value='zzzzzzz' /><label for='ChildList_0'>zzzzzzz</label></td>
</tr>
<tr>
<td><input id='ChildList_1' type='radio' name='ChildList' value='xxxxxxx' /><label for='ChildList_1'>xxxxxx</label></td>
</tr>
</table>";
Will produce this list and sublist:

But it won't be truly server-side control. If you need just client-side access to this list - this approach may work for you. Otherwise, as I mentioned in my comments - consider a user control where you can build your own hiearchy out of ASP.NET tables and RadioButtons.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With