根据数据库生成了一组按钮,如何写按按钮的事件,事件中要根据按钮的TEXT值调用后台的一个方法
解决方案 »
- 如何自动生成静态页面
- TextBox控件的change事件
- 【求助】很急,关于RDLC报表表达式的问题
- DataGrid中编辑按钮中的更新事件中,怎样获得隐藏列的值
- 谁有基于B/S实现的二叉树的例子,调试成功马上结贴
- 这条SQL语句我实在写不来了
- 如何在类中使用response.redirect?
- 程序的最后一个bug了,但是想到头晕都没有解决,关于在不同电脑上创建制定文件夹
- asp.net Winform 将GridView数据导出成Excel----求大侠帮忙
- ImageButton 的用法,绑定包含图片的文件夹
- 各位大哥,有一段登录时的代码小弟我看不懂,帮忙看看解释一下!
- <和<的关系,以及"和"的关系
然后this.btnGiveMealConfirm.Click += new System.EventHandler(this.btnGiveMealConfirm_Click);
就可以了这个this.btnGiveMealConfirm_Click市委托方法
protected void Page_Load(object sender, EventArgs e)
{
Button btn1 = new Button();
btn1.ID = "btn1";
btn1.Text = "btn1";
btn1.Click += new EventHandler(btn_Click); Button btn2 = new Button();
btn2.ID = "btn2";
btn2.Text = "btn2";
btn2.Click += new EventHandler(btn_Click); this.form1.Controls.Add(btn1);
this.form1.Controls.Add(btn2);
} void btn_Click(object sender, EventArgs e)
{
//此处获取button的text
string text = ((Button)sender).Text;
if (text == "btn1")
{
Response.Write("btn1 clicked");
}
else if (text == "btn2")
{
Response.Write("btn2 clicked");
}
}
{
Button tb = new Button();
this.form1.Controls.Add(tb);
tb.ID = "CmdTest";
tb.Text = "Test";
tb.Click += new System.EventHandler(Button1_Click);
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write(((Button)form1.FindControl("CmdTest")).Text);
}