ASP.NET: Get selected RadioButton’s value in specific GroupName

RadioButton selRB = radioButtonsContainer.Controls.OfTypeRadioButton>().FirstOrDefault(rb => rb.Checked);if(selRB != null){    int registrationTypeAmount = Convert.ToInt32(selRB.ToolTip);    string cbText = selRB.Text;}

where radioButtonsContainer is the container of the radiobuttons.


If you want to ensure you get RadioButtons with the same group, you have 2 options:

  • Get them in separate containers
  • Add the group filter to the lamdba expression, so it looks like this:

    rb => rb.Checked && rb.GroupName == "YourGroup"

Update 2

Modified the code to make it a little more fail proof by ensuring it won’t fail if there’s no RadioButton selected.

Leave a Reply

Your email address will not be published. Required fields are marked *