简体   繁体   中英

Check radio buttons from dynamic form

I've created a form on wich I load several questions from a database, the questions are loaded by category on different pages, now that I have that I wan't to check that all of the radiobuttons have a value that is they should not be null (unchecked state).

So if Radio buttons are all checked then I can proceed to the next page with the next category of questions,

Q) How how can I check radio button state since questions are loaded from database and in a future in Y category can be N numbers of questions.

If you're generating the radio buttons dynamically and want to verify that they all have values, you should wrap in a container like a Panel or a PlaceHolder :

<asp:PlaceHolder ID="PlaceHolder1" runat="server">
    <!-- put the dynamically generated radio buttons here -->
</asp:PlaceHolder>

By putting them in a container, you can then do something like this:

foreach (RadioButton radio in PlaceHolder1.Controls.OfType<RadioButton>())
{
    //set the enabled state based on whether a value is assigned
    radio.Enabled = radio.Value.Length > 0;
} 

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