Link to home
Start Free TrialLog in
Avatar of codemonkey2480
codemonkey2480

asked on

Looping through a panel with unknown number of Radiobuttons/Checkboxes

I have panel that adds dynamic radiobuttons based on records from a database table.
Example: If table has departments D1,D2,D3 then there will be 3 radiobuttons on the UI.

I would like to be able to go through all the radiobuttons inside the panel and find out which one is checked. If say D1 is checked then get the text property value of that radio button.

If they are checkboxes and multiple selections are allowed, How can I approach that?

Please let me know
Avatar of fabianbaptista
fabianbaptista

you can do this inside your panel:


 foreach (Control RadioBut in panel.Controls)
            {
                if (RadioBut is RadioButton)
                {
                    bool isChecked = (RadioBut as RadioButton).Checked;
                }
            }

hope this helps
ASKER CERTIFIED SOLUTION
Avatar of fabianbaptista
fabianbaptista

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rajeeshmca
The same logic u have implemented for radio button can be implemented for check box also...

The only thing is concatenate the selected check boxes value using a splitter like...


string value;
for loop comes here ....

value  += chkBox1.selectedItem + "^^"

for loop ends here....