Click here to Skip to main content
15,908,020 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I want to enable a button depending on the selected item from the radio button list;I have written the following code in Selected_Item_Changed event of the radbtnlist.But it is not working,what can be the problem?

RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (RadioButtonList1.SelectedItem.Value == "I Agree")
{
btnSubmit.Visible = true;
}
else
{
btnSubmit.Visible = false;
}
}
Posted

Hello,
Disable the button on form load like this
private void Form1_Load(object sender, EventArgs e)
        {
            button1.Enabled = false;
        }


and then use the checked_changed event of radio button to do your trick

private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton1.Checked == true)
            {
                button1.Enabled = true;
            }
        }


Do rate my answer once you find it useful
Thanks & Regards
Radix :rose:
 
Share this answer
 
Comments
avishekrc 19-May-10 1:22am    
but I want to make the btn enabled depending on the specific item chosen from the radbtnlist...
You might want to look at the CheckChanged event.
 
Share this answer
 
Comments
avishekrc 19-May-10 1:20am    
nope,not working..can u pls write the above code in CheckChanged event?I have TextChanged event,I tried to write within that,but did not work..
Ok like u said that u want to make the button enable on selecting a particular item from the radiobutton list right then hers an example for you
In the below code i have again made the button disable on form load
private void Form2_Load(object sender, EventArgs e)
        {
            button1.Enabled = false;
        }


now all you had to do is use the SelectedIndexChanged event of your radio button in my code i have used a checkbox list both are same and will work fine the only difference is that in checkbox u can select multiple item but in radio button you cannot do that

private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
//now here if the first item in the checklistbox is selected then the button will be enabled
            if (checkedListBox1.SelectedIndex == 0)
            {
                button1.Enabled = true;

            }
              else
            {
                button1.Enabled = false;
            }
            
        }

Now all u have to do is use this logic to enable that button on the selected index of your radio button, here 0 indicates the first item in my checkbox list...
Do rate my answer once you find it useful
Thanks & Regards
Radix :rose:
 
Share this answer
 

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