【问题标题】:ASP.NET - How to put items of Radiobuttonlist into HTML tagASP.NET - 如何将 Radiobuttonlist 的项目放入 HTML 标记中
【发布时间】:2017-10-20 06:16:10
【问题描述】:

我想将 Radiobuttonlist 的项目放入td 标签中。

<td><asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatLayout="Table" RepeatDirection="Horizontal"></asp:RadioButtonList></td>

这是结果。这是从数据库加载的矩阵、行和列。(已设置单选按钮列表数据源)。

我将 RadioButtonList 放入td 标签中:所有项目都包含在一个单元格中。 当每个项目包含在一个单元格中时,我的矩阵将是完整的。

Itemtemplate 用于 RadioButtonList 之类的中继器吗?

【问题讨论】:

标签: asp.net radiobuttonlist


【解决方案1】:

创建您自己的自定义单选按钮列表控件:

namespace Controls
{
    public class MyRadioButtonList : RadioButtonList
    {

        protected override void RenderItem(System.Web.UI.WebControls.ListItemType itemType, int repeatIndex, System.Web.UI.WebControls.RepeatInfo repeatInfo, System.Web.UI.HtmlTextWriter writer)
        {
            writer.Write("<td>");
            base.RenderItem(itemType, repeatIndex, repeatInfo, writer);
            writer.Write("</td>");
        }
    }

}

并照此使用。

首先将控件注册到页面,或者用户控件:

然后使用控件:

它是服务器端的一个基本单选按钮列表控件,所以就像现在一样使用它。

【讨论】:

  • 它就像一个普通的单选按钮列表。将控件包含到您的页面中,这就是您所要做的。
  • 谢谢。我很明白。但是我遇到了麻烦:&lt;%@ Register Assembly="DotNetNuke.Web" Namespace="DotNetNuke.Web.Controls" TagPrefix="cc1" %&gt;我正在使用 Dotnetnuke,它不起作用???
  • 查看此内容以了解如何将程序集注册到页面 msdn.microsoft.com/en-IN/library/c76dd5k1(v=vs.85).aspx。 。我相信您已将控件的代码放在类文件中
  • 是的,我在 webform 后面的代码中放入了一个底部类文件。
  • 如果你成功了,请将我的答案标记为答案。谢谢!
猜你喜欢
  • 2014-09-23
  • 1970-01-01
  • 1970-01-01
  • 2023-03-18
  • 2010-12-21
  • 1970-01-01
  • 2010-10-02
  • 1970-01-01
  • 2022-11-23
相关资源
最近更新 更多