简体   繁体   中英

how to add checkbox element inside a radiobutton list

my code looks something like this-:

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

I want to show <asp:CheckBox> element after the second list item is selected. So, the checkbox needs to appear between second and third list item. Is there anyway to do this? Right now I'm showing the checkbox after the radiobuttonlist element.

That is not possible with a RadioButtonList . You will have to use single RadioButtons with GroupName to create your own.

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

UPDATE

It is sort of possible in a hacky way. And if it is useful depends on what you want to do with that checkbox. Make the Text of a ListItem a html checkbox.

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

Then move it over the radio button

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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