如何在按钮事件中编写单选按钮事件代码 [英] how to write radiobutton event code in button event

查看:144
本文介绍了如何在按钮事件中编写单选按钮事件代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在按钮事件中编写单选按钮事件代码....我想在单击按钮时为一个单选按钮插入数据,并为另一个单选按钮选择数据,但是两个代码仅在一个按钮事件中显示

how to write radiobutton event code in button event....i want to insert data for one radio button on clicking the button and select data for another radio button but bothe codes shd be only in one button event

推荐答案

要订阅两个事件,请使用以下代码:
To subscribe both events use this code:
public Form1()
{
  InitializeComponent();
  this.radioButton1.Click += new System.EventHandler(this.radioButton_Click);
  this.radioButton2.Click += new System.EventHandler(this.radioButton_Click);
}


要处理事件,它应该起作用:


To handle the events this should work:

private void radioButton_Click(object sender, EventArgs e)
{
   if ((RadioButton)sender == radioButton1)
   {
      //insert data
   }
   else
   {
      //select data
   }
}


请这样写
private void Button1_Click(object sender, EventArgs e)
{
if(radiobutton1.checked)
{
//insert query 1
}
{
//insert query 2
}
}


注意:

首先为两个相同的单选按钮设置组名.


note:

First set group name for two radiobutton same.


这篇关于如何在按钮事件中编写单选按钮事件代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆