【问题标题】:How can I prevent asp:RadioButtonList from rendering a HTML-Table? [duplicate]如何防止 asp:RadioButtonList 呈现 HTML 表? [复制]
【发布时间】:2011-01-12 03:12:06
【问题描述】:

我想呈现一个简单的 - 控件列表。 我的 ASP.NET 代码隐藏如下:

RadioButtonList list = new RadioButtonList();
                    list.ID = rbl.name;
                    list.CssClass = rbl.cssClass;

                    foreach (radio radio in rbl.radio)
                    {
                        ListItem li = new ListItem();
                        li.Text = radio.label;
                        li.Value = radio.value;
                        li.Selected = radio.@checked;
                        list.Items.Add(li);

                    }

但 RadioButtonList 会自动呈现 HTML 表格。如果我使用 HtmlInputRadioButton 一切正常,但它在 RenderControl() 上崩溃

【问题讨论】:

    标签: c# asp.net radiobuttonlist


    【解决方案1】:

    你应该看看RadioButtonList.RepeatLayout Property

    使用此属性可指定 RadioButtonList 控件中的项目是否显示在表格中。如果此属性设置为 RepeatLayout.Table,则列表中的项目将显示在表格中。如果此属性设置为 RepeatLayout.Flow,则列表中的项目将显示为没有表格结构。

    【讨论】:

    • 非常感谢。这是我见过的最快的完美答案。
    • 我希望 label 环绕 checkbox
    【解决方案2】:

    除了 Rubens Farias 的答案之外,ASP.NET 4 为 RadioButtonList.RepeatLayout、OrderedList 和 UnorderedList 添加了两个新选项。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-10-14
      • 1970-01-01
      • 2016-01-27
      • 2012-10-17
      • 2012-07-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多