界面上三个radioButton控件,在程序中我想根据哪个radioButton被点中后执行相应方法,if语句实现如下 if (radioButton1.Checked)
{
//方法
}
else if (radioButton2.Checked)
{
//
}
else if (radioButton3.Checked)
{
//
}
但是我想改成swith case语句 应该怎么改写???
{
//方法
}
else if (radioButton2.Checked)
{
//
}
else if (radioButton3.Checked)
{
//
}
但是我想改成swith case语句 应该怎么改写???
解决方案 »
- 未能找到任何适用于指定的区域性或非特定区域性的资源。
- 共享内存问题
- ★真心请教个关于练字的问题.我估计很多程序员都有这个问题.
- 關於Remoting數據同步問題,請高手指點,非常感謝
- 新手求助一个for循环的问题
- 求救 显示一个窗体,另外一个窗体如何推出的语句1
- 我有一个关于WinForm的问题,请大家帮帮忙?谢谢!
- 请大家提供几个winform的网站,国内或是国外均可!!!
- c#中如何处理smallmoney???
- listview 有没有像DataGrid一样可以设属性点击head可以进行排序的?
- c# richTextBox问题
- java用httpClient post方式传数据,ASP.NET怎么接收数据?
int i = 0;
把这几个check放到一个group中,获取其中的值赋予i,然后用switch来处理i的不同值的情况
radText=radioButton1.Text;
radText=radioButton2.Text;
radText=radioButton3.Text;
swith(radText)
{
case "":
//
break;
case "":
//
break;
case "":
//
brea;
}
<asp:RadioButtonList ID="radl" runat="server">
<asp:ListItem Value="1" Selected="True">选择1</asp:ListItem>
<asp:ListItem Value="2">选择2</asp:ListItem>
<asp:ListItem Value="3">选择3</asp:ListItem>
</asp:RadioButtonList>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />protected void Button1_Click(object sender, EventArgs e)
{
int selectValue = Convert.ToInt32(radl.SelectedValue);
switch (selectValue)
{
case 1:
Response.Write(selectValue);
break;
case 2:
Response.Write(selectValue);
break;
case 3:
Response.Write(selectValue);
break;
}
}
{
int selectValue = Convert.ToInt32(radl.SelectedValue);
switch (selectValue)
{
case 1:
Response.Write(selectValue);
break;
case 2:
Response.Write(selectValue);
break;
case 3:
Response.Write(selectValue);
break;
}
}
{
CheckBox checkbox = sender as CheckBox;
if (checkbox != null)
{
bool check = checkbox.Checked;
if (check)
{
switch (checkbox.Name)
{
case "checkbox1":
break;
case "checkbox2":
break;
case "checkbox3":
break;
default:
break;
}
}
}
}
如果你讲的是web项目,楼上已经给出建议了
RadioButton curBtn = (RadioButton)sender;
if(curBtn.checked){
switch(curBtn) {
case radioButton1:
//do
break;
case radioButton2:
//do
break;
case radioButton3:
//do
break;
default:
break;
}
}
switch (str)
{
case "radioButton1":
MessageBox.Show("radioButton1");
break;
case "radioButton2":
MessageBox.Show("radioButton2");
break;
case "radioButton3":
MessageBox.Show("radioButton3");
break;
default:
break;
}
2. 在每次 radio 选中的时候触发 CheckChanged 事件,
在这个事件里面设置全局变量的值:rdtype = .....
3. 写 switch,怎么实现你懂的。
switch (rdtype)
{
case R1: .....
case R2: .....
case R3: .....
}
{
if (ctr is RadioButton)
{
((RadioButton)ctr).CheckedChanged += radio_CheckedChanged;
}
}
2.
private void radio_CheckedChanged(object sender, EventArgs e)
{
RadioButton radio = sender as RadioButton;
if (!radio.Checked)
{
return;
}
switch (radio.Name)
{
case "radA":
MessageBox.Show("a");
break;
case "radB":
MessageBox.Show("b");
break;
case "radC":
MessageBox.Show("c");
break;
}
}