微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何使用自定义参数调用 ASP.NET DropdownList SelectedIndexChanged 事件处理程序

如何解决如何使用自定义参数调用 ASP.NET DropdownList SelectedIndexChanged 事件处理程序

我需要调用带有自定义参数的 DropDownList。由于我想向事件处理程序发送一些自定义事件(自定义数据),因此想要连接或拦截 DropDownList.SelectedindexChanged 事件,以便我可以从中提取信息。

代码中的某个点:

dropdownList.Selectedindexchanged += new EventHandler(AzureService_CommonResourceGroupSelectedindexChanged);

  protected void AzureService_CommonResourceGroupSelectedindexChanged(object sender,MyEvnetArgs e)
    {
        // Want to populated other dynamic ASP.NET Dropdown control on the same dialog. So that's why need to get the corresponding control name info here.
    }

知道如何实现吗?但不知道如何将 MyEventArgs 传递给处理程序。是否有可能以某种方式挂钩或拦截呼叫? 将不得不得到答案。

编辑

AzureService_CommonResourceGroupSelectedindexChanged handler should receive as Eventargs extra data which I can use to query what kind of dropdownlist is intended to be cascade in the course of the click of the first one. I am working on cascading drop-down Boxes.

Dropdown 1 - 单击应该级联另一个下拉框(必须通知其处理程序必须向谁填充其他下拉列表)。

![enter image description here

此处将从源填充下拉列表 1 数据。用户将从下拉列表 1 列表中选择一些内容,因此其他相关下拉列表将被填充。 Handler 将进一步使用 drop down2 和 drop down3 的 Html 实例来填充其数据

所以,我需要以某种方式通知 dropdwon1 它必须填充的其他下拉列表。

谢谢

解决方法

您可以提供自己的委托并链接处理程序。

dropdownList.SelectedIndexchanged += new EventHandler(MyEventHandler);

protected void MyEventHandler(object sender,EventArgs e)
{
    var e2 = new MyEventArgs { SomeVariable = "Whatever" };
    AzureService_CommonResourceGroupSelectedIndexChanged(sender,e2);
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。