Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get which radio button is checked from a groupbox?

Tags:

I have these groupboxes:

Enter image description here

I want to run some code according to checked true state of a radio button like:

string chk = radiobutton.nme; // Name of radio button whose checked is true switch(chk) {     case "Option1":         // Some code         break;      case "Option2":         // Some code         break;      case "Option3":         // Some code         break; } 

Is there any direct way so that I can only get the name of the checked radio button?

like image 859
Amit Bisht Avatar asked Aug 31 '13 10:08

Amit Bisht


People also ask

How do you check the radio button is checked?

To find the selected radio button, you follow these steps: Select all radio buttons by using a DOM method such as querySelectorAll() method. Get the checked property of the radio button. If the checked property is true , the radio button is checked; otherwise, it is unchecked.

How check radio button is checked or not in VB net?

The Checked property of the radio button is used to set the state of a radio button. You can display text, image or both on radio button control. You can also change the appearance of the radio button control by using the Appearance property.

How do I access radio buttons?

Get the value of selected radio button: querySelector() Remember you need to specify the name property of the radio button in HTML code. It is used as document. querySelector('input[name="JTP"]:checked') inside the <script> tab to check the selected radio button value from the group of radio buttons.

How do I check if a radio is selected in HTML?

Use document. getElementById('id'). checked method to check whether the element with selected id is check or not.


1 Answers

You can find all checked RadioButtons like

var buttons = this.Controls.OfType<RadioButton>()                            .FirstOrDefault(n => n.Checked); 

Also take a look at CheckedChanged event.

Occurs when the value of the Checked property changes.

like image 117
Soner Gönül Avatar answered Sep 17 '22 13:09

Soner Gönül