首页 > 解决方案 > 如何在单选按钮列表中添加复选框元素

问题描述

我的代码看起来像这样:

<asp:RadioButtonList>
  <asp:ListItem></asp:ListItem>
  <asp:ListItem></asp:ListItem> //ToDo
  <asp:ListItem></asp:ListItem>
</asp:RadioButtonList>

我想<asp:CheckBox>在选择第二个列表项后显示元素。因此,复选框需要出现在第二个和第三个列表项之间。有没有办法做到这一点?现在我在单选按钮列表元素之后显示复选框。

标签: asp.net

解决方案


这是不可能的RadioButtonList。您将不得不使用单个 RadioButtonsGroupName来创建您自己的。

<asp:RadioButton ID="RadioButton1" runat="server" GroupName="MyGroup" />
<asp:CheckBox ID="CheckBox1" runat="server" />
<asp:RadioButton ID="RadioButton2" runat="server" GroupName="MyGroup" />
<asp:RadioButton ID="RadioButton3" runat="server" GroupName="MyGroup" />

更新

这有点可能以一种骇人听闻的方式。如果它有用取决于你想用那个复选框做什么。使TextListItem 的 html 复选框。

RadioButtonList1.Items[1].Text = "<input type=\"checkbox\" id=\"checkBoxInsideList\" class=\"RadioButtonListWithCheckbox\">";

然后将其移到单选按钮上

<style>
    .RadioButtonListWithCheckbox {
        margin-left: -16px;
    }
</style>

推荐阅读