哪个事件写以下代码? [英] Which event to write the following code?
问题描述
我想根据单选按钮列表中的选定项目启用按钮;我在radbtnlist的Selected_Item_Changed事件中编写了以下代码.但是它不起作用,可能是什么问题?
RadioButtonList1_SelectedIndexChanged(对象发送者,EventArgs e)
{
如果(RadioButtonList1.SelectedItem.Value ==我同意")
{
btnSubmit.Visible = true;
}
其他
{
btnSubmit.Visible = false;
}
}
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;
}
}
推荐答案
你好,
像这样禁用表单加载上的按钮
Hello,
Disable the button on form load like this
private void Form1_Load(object sender, EventArgs e)
{
button1.Enabled = false;
}
然后使用单选按钮的checked_changed事件完成操作
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;
}
}
一旦找到有用的答案,就对我的答案进行评分
谢谢&问候
基数:rose:
Do rate my answer once you find it useful
Thanks & Regards
Radix :rose:
您可能想看看CheckChanged
好吧,就像你说的那样,你想使按钮在选择特定项目时启用从单选按钮列表中,然后为您提供示例
在下面的代码中,我再次使按钮在表单加载时禁用
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; }
现在您要做的就是在我的代码中使用单选按钮的SelectedIndexChanged事件,我使用了一个复选框列表,两者相同并且可以正常工作,唯一的区别是在复选框中您可以选择多个项目,但是在单选按钮中您不能执行那
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; } }
现在您要做的就是使用此逻辑在单选按钮的选定索引上启用该按钮,这里0表示我的复选框列表中的第一项...
一旦找到有用的答案,就对我的答案进行评分
谢谢&问候
基:rose:
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:
这篇关于哪个事件写以下代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!