簡體   English   中英

如何在單選按鈕列表中添加復選框元素

[英]how to add checkbox element inside a radiobutton list

我的代碼看起來像這樣:

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

我想在選擇第二個列表項后顯示<asp:CheckBox>元素。 因此,該復選框需要出現在第二個和第三個列表項之間。 反正有這樣做嗎? 現在,我正在單選按鈕列表元素后面顯示復選框。

使用RadioButtonList是不可能的。 您將必須使用帶有GroupName單個RadioButton來創建自己的RadioButton。

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

更新

這很可能是一種駭人聽聞的方式。 並且是否有用取決於您要對該復選框執行的操作。 使ListItem的Text為html復選框。

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

然后將其移到單選按鈕上

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM