阻止<span>标记ASP.NET服务器控件</span>

时间:2014-05-05 10:06:45

标签: c# asp.net

我对此span标记有疑问。它们是生成但我不想要它们。我怎么能删除它们?

我有以下代码

<asp:RadioButtonList ID="rbl_items" runat="server" RepeatLayout="Flow"  Visible="true" ClientIDMode="Static"  >


</asp:RadioButtonList>

呈现此

<span> 
<input> 
<label> 
<br> 
<input> 
<label>
<br> 
(...)
< /span>

我想要像

这样的东西
   < label>< input (radio)>< /label>
   < label>< input (radio)>< /label>

换句话说,我怎样才能删除&lt;跨度&GT;标签和如果可能的结构,渲染html就像客户想要的那样(如我所示)。

谢谢

1 个答案:

答案 0 :(得分:0)

摆脱跨度的一种方法是遵循提到的Here

技术

另一种方法是,使用html的输入控件并放置runat =“server”和ID属性并在后面的代码中使用。

另一种方法是使用这样的东西:

<ul ID="rbl_items" runat="server" clientidmode="Static" style="list-style: none;"></ul>

Code Behind:

int count = 0;
foreach (var yourObj in YourList)
        {
            HtmlGenericControl li = new HtmlGenericControl("li");
            HtmlInputRadioButton radioButton = new HtmlInputRadioButton
            {
                Value = yourObj,
                Name = "controlGroup",
                ID = "controlID" + count
            };
            li.Controls.Add(radioButton);
            Label label = new Label { Text = yourObj, CssClass = "YourCSSClass", AssociatedControlID = "controlID"+count };
            li.Controls.Add(label);
            rbl_items.Controls.Add(li);
            count++;
        }

您可以稍后为ul和li设置样式。

相关问题