如何将多个事件处理程序绑定到按钮? [英] How to bind multiple event handlers to a button?

查看:53
本文介绍了如何将多个事件处理程序绑定到按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有2个txtboxes,3个ddl绑定到gridview。

当用户输入值时,gridview根据它绑定。

我必须创建一个按钮,以便当我点击按钮时,所有这些ddl和txtbox都会被过滤并显示在gridview中。



gridview值来自数据表。

any1可以帮助我吗?

Hi I have 2 txtboxes ,3 ddl which are binded to the gridview.
When the user enters the value the gridview is binded according to it.
I have to create a button so that all these ddl nd txtboxes get filtered and displayed in the gridview when i click on the button.

The gridview values are from datatable.
Can any1 help me ?

推荐答案

在C#中,事件总是被添加到事件实例的调用列表中使用operator + =。没有别的办法。您应该在同一个事件实例(即:相同的对象实例,同一个事件成员)上使用此运算符,然后再使用一次。 C#中最短的代码(在较新的版本中使用 lambda 语法和类型推断它甚至更好)可能是这样的:

In C#, the event is always added to the invocation list of an event instance using the operator +=. There is no any other way. You simply should use this operator on the same event instance (that is: same object instance, same event member) more then once. The shortest possible code in C# (in newer versions using lambda syntax and type inference it's even better) is probably this:
myButton.Click += delegate(object sender, System.EventArgs eventArgs) {
   // do something
}

myButton.Click += delegate(object sender, System.EventArgs eventArgs) {
   // do something else
}



它会通过向其添加两个处理程序来创建与首次创建多播委托相同的效果,然后使用+ =将此多播委托实例添加到事件实例的调用列表中。我会把它留给你的家庭锻炼。 :-)



您可能会感到困惑,因为您只使用设计师添加了活动。与设计师一起做所有事情都很糟糕。如果你开始用自己的双手进行真正的编程,了解事情是如何工作的,那会更好。此外,在很多情况下使用设计师是完全不切实际的。



-SA


这篇关于如何将多个事件处理程序绑定到按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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