Click here to Skip to main content
15,902,635 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
how deselect all selected radiobuttons in a panel on a button click?
Posted

If you use
RadioButtonList has a method ClearSelection.

protected void Save_Click(object sender, EventArgs e)
{
RadioButtonList1.ClearSelection();
}

This will resolve your issue.

or

The code problem is that in a mutually exclusion radio buttons group you need to initially select one of them.

So, I believe there are two ways of solving the problem:

Keep the radio buttons groud. Add a "none" button to the set, so that it works as if none of the other three are selected. And initially select this "none" button.

change the radio buttons to check boxes, so the user might select and deselect each of them. Then implement your own exclusion logic. I don't recommend this one.
 
Share this answer
 
C#
If (control.CheckedStatus == CheckedStatus.Checked)
{
   control.CheckedStatus = CheckedStatus.Unchecked;
}



or other way you can use delegates.

C#
delegate void CheckOrUncheckRadioButtonEventHandler(RadioButton rb, bool isChecked);
        private void CheckOrUncheckRadioButton(RadioButton rb, bool isChecked)
        {
            try
            {
                if (rb.InvokeRequired)
                {
                    CheckOrUncheckRadioButtonEventHandler d = new CheckOrUncheckRadioButtonEventHandler(CheckOrUncheckRadioButton);
                    this.Invoke(d, new object[] { rb, isChecked });
                }
                else
                {
                    rb.Checked = isChecked;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }




Regards,
Praveen Nelge
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900