我们有一个列表,它正在生成服务器端,然后使用<asp:RadioButtonList...它来显示它.
但是,我们如何在其中一个项目之后添加一些HTML?
我们的想法是,如果生成其中一个,就会生成一些"子"单选按钮.
谢谢
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>
Run Code Online (Sandbox Code Playgroud)
创建您自己的自定义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
Run Code Online (Sandbox Code Playgroud)
并使用它.
首先将控件注册到页面或用户控件:
<%@ Register Assembly="(projectnamespace)" Namespace="(projectnamespace).Controls" TagPrefix="cc1" %>
Run Code Online (Sandbox Code Playgroud)
然后使用控件:
<cc1:MyRadioButtonList ID="rdolist" runat="server" />
Run Code Online (Sandbox Code Playgroud)
它是服务器端的基本radiobuttonlistcontrol,所以只需像现在一样使用它.
| 归档时间: |
|
| 查看次数: |
1075 次 |
| 最近记录: |