如何为15个链接按钮单击事件实现相同的代码(How to implement same code for 15 linkbutton click events)

   IT问题网   2021-01-20 00:00:00

问 题

嗨,



我想以水平方式将树绑定到2级

因为我使用了15个静态链接按钮

当我点击任何链接按钮然后我需要显示该特定用户的树。





我想为这15个不同的linkbutton点击事件实现相同的功能。



是否有可能实现它而无需在代码中写入15个点击事件

解决方案

将ur代码粘贴到用户定义的函数中并在所有linkbutton click事件中调用它

event只是一个指向处理的method的委托它(它可能会有更多,但这一部分很重要)。这使得可以为同一个方法提供多个事件点(或监听)。

例如在vb中使用以下代码:

  addhandler  linklabel1.click, addressof  linklabel_click 
addhandler linklabel2.click, addressof linklabel_click
addhandler linklabel3.click, addressof linklabel_click

私有 sub linklabel_click( byval sender 作为 对象 byval e as eventargs)
' 这里的代码,获取通过强制转换点击的linklabel发件人。
结束 sub


这与c#中的以下代码类似。

 linklabel1.click + = linklabel_click; 
linklabel2.click + = linklabel_click;
linklabel3.click + = linklabel_click;

private void linklabel_click(对象发件人,eventargs e){
// 您的代码在这里,获取linklabel点击投射发件人。
}


或者,在vb中,您可以使用handles关键字,如下所示:

 私有  sub  linklabel_click( byval 发件人作为 对象 byval  e  as  eventargs)句柄 linklabel1.click,linklabel2.click,linklabel3.click 
' 您的代码在此处获取通过投射发件人而点击的linklabel。 / span>
结束 sub


我从未使用过asp.net,但我很确定它的工作原理相同:)

标签:如何链接按钮单击事件实现相同代码



分享:

  • 微信
  • QQ好友
  • QQ空间
  • 新浪微博


热门推荐

在数据网格中更改字段的名称(change field's name in a datagrid)

problem how can i change name of the each header columns ...

使用多个mdi表单(working with mutiple mdi forms)

problem hello i have a c sharp application, which contai ...

更改Html对象Zindex(Change Html Object Zindex)

problem hi all i have an object in my page. i ...

GDI +中发生一般错误的问题。(problem with A generic error occurred in GDI+.)

problem hi all when i want save image from fileupload fa ...

编写非肥皂网服务(Writing Non soap web service)

problem please let me know how to write a non ...

在asp.net和c#中动态创建按钮(Dynamically created button in asp.net and c#)

problem hi, i am creating online examination ...

文件上传问题,找不到文件(File Upload problem, file not found)

problem hi, from my asp.net form, i am trying ...

请在下拉列表中解决错误(please solve error in dropdown list)

problem please solve the error i have 2 dropdownlist. in ...

更改属性上的ReadOnly属性不起作用(Change ReadOnly attribute on property doesn't work)

problem i''ve tried to change a readonly attr ...

我如何分割我的表格(how do i split my form)

problem ok i want to split my form in half so on the left ...

将templatefield动态添加到gridview(adding templatefield dynamically to gridview)

problem give the tutorial to add template field, controls ...

在c#的帮助下导出pdf文件(Export pdf File with the help of c#)

problem how to convert more then one pdf file ...

计算中间日期并在gridview中显示它(calculate inbetween date and show it in gridview)

problem hello friends, by using date time pi ...

为它的学生项目(Project for an it student)

problem hi, i m an bsc it student ,as many of you will kn ...

单击更改图标通知(Change Icon Notify on Click)

problem is possible changer notifyicon1 on click the prog ...

如果用户已经登录,则在同一浏览器中重定向到主页asp .net c#(Redirect to Home page if user already logged in, in same browser asp .net c#)

problem i want to make application that if user in logged ...

需要帮助来使用MySqlTransaction(Need help in using MySqlTransaction)

problem hi all i would like to use mysqltransaction in my ...

如何使用VBscript导航Windows注册表树(How to navigate Windows registry tree with VBscript)

problem does anyone know how to go about navigating the w ...

silverlight内存泄漏(silverlight memory leak)

problem hi, i was creating a dependencyproperty changed w ...

如何在json中获取单个元素(How to get single element in json)

problem in wcf service i am getting json response in that ...