我们可以为用于相同操作但导致唯一标识的控件的相似Web控件的列表设置通用的默认事件吗? [英] can we set a common default events for the list of similar webcontrols which are used for the same operations but resulted in a uniquely identified controls

查看:70
本文介绍了我们可以为用于相同操作但导致唯一标识的控件的相似Web控件的列表设置通用的默认事件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们是否可以为用于相同操作但导致唯一标识的控件的相似Web控件的列表设置通用的默认事件

请帮助我

can we set a common default events for the list of similar web controls which are used for the same operations but resulted in a uniquely identified controls

please help me

推荐答案

如果所有控件的类型均为DropDowList,则只需创建事件处理程序,该事件处理程序必须具有DropDownList.SelectedItemChanged的正确签名.
只需将此事件处理程序分配给您的所有DropDownLists.

事件处理程序的第一个参数是object类型;它指的是引发事件的控件.在事件处理程序中,只需将此对象转换为DropDownList类型的变量,然后从那里进行逻辑处理即可.

例子:

If all your controls are of type DropDowList, you just have to create your event handler, which must have the correct signature for the DropDownList.SelectedItemChanged.
Just assign this event handler to all of your DropDownLists.

The first parameter of the event handler is of type object ; it refers to the control that has raised the event. In your event handler, just cast this object to a variable of type DropDownList, and then go with your logic from there.

Example :

private void DropDownList_SelectedIndexChanged(object sender, EventArgs e)
{
   DropDownList ddl = (DropDownList)sender;
   // Go on with your logic, using ddl variable just created
}



这样,您所有的DropDownLists SelectedIndexChanged事件都将由相同的事件处理程序处理.

希望对您有所帮助.



This way all your DropDownLists SelectedIndexChanged events will be handled by the same event handler.

Hope this helps.




您可以处理所有常见类型的控件引发的事件

在这里,我给出了一些想法,如何在单个处理程序中处理多个控制事件

Hi,

you can handle all events which are raised from common type of controls

Here I''m giving some idea how to handle multiple control events in single handler

 <table width="300"><tr>
  <td>
      <asp:linkbutton id="LinkButton2" runat="server" commandargument="First" onclick="LinkButton2_Click" xmlns:asp="#unknown">First</asp:linkbutton></td>
  <td>
      <asp:linkbutton id="LinkButton3" runat="server" commandargument="Prev" onclick="LinkButton2_Click" xmlns:asp="#unknown">Prev</asp:linkbutton></td>
  <td valign="bottom">
</td></tr></table>



就像上面的代码一样,我的网络控件中有太多的链接按钮
我可以在单个处理程序中处理所有事件,例如是否有链接点击
它只能引发LinkBut​​ton2_Click事件

在我的单曲中,我为所有linkbutton功能编写了代码



Like in the above code i''ve too many linkbuttons in my webcontrol
I can handle all events in my single handler like if any linke clicks
it can raise only LinkButton2_Click event

And in my single I write code for all linkbutton features

protected void LinkButton2_Click(object sender, EventArgs e)
  {
      if (((LinkButton)sender).CommandArgument.ToString() == "First")
      {
          ReqPageNo = "1";
      }
      if (((LinkButton)sender).CommandArgument.ToString() == "Prev")
      {
          if (int.Parse(crntpage.Value) == 1)
          {
              ReqPageNo = "1";
          }
          else
          {
              ReqPageNo = (int.Parse(crntpage.Value) - 1).ToString();
          }
      }
      if (((LinkButton)sender).CommandArgument.ToString() == "Next")
      {
          if (int.Parse(crntpage.Value) == int.Parse (TotalPageNo))
          {
              ReqPageNo = TotalPageNo;
          }
          else
          {
              ReqPageNo = (int.Parse(crntpage.Value) + 1).ToString();
          }
      }
      if (((LinkButton)sender).CommandArgument.ToString() == "Last")
      {
          ReqPageNo = TotalPageNo;
      }
      Click(this, e);
  }



这样,您可以在单个处理程序中处理任何事件

我希望你能理解我说的话

最好的



Like this you can handle any event in single handler

I hope you understood what I said

All the Best


这篇关于我们可以为用于相同操作但导致唯一标识的控件的相似Web控件的列表设置通用的默认事件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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