繁体   English   中英

防止<span>标签ASP.NET服务器控件</span>

[英]Prevent <span> tags ASP.NET server control

我的跨度标签有问题。 它们是生成的,但是我不想要它们。 我如何删除它们?

我有以下代码

<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>

换句话说,我该如何删除<span>标记,并且如果可能的话,将呈现的html构造为客户端想要的形式(如我所示)。

谢谢

摆脱跨度的一种方法是遵循此处提到的技术

另一个可能是,使用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设置样式。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM