【问题标题】:How to call ASP.NET DropdownList SelectedIndexChanged event handler with custom arguments如何使用自定义参数调用 ASP.NET DropdownList SelectedIndexChanged 事件处理程序
【发布时间】:2021-09-21 23:56:19
【问题描述】:

我需要调用带有自定义参数的 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 - 点击后应该级联另一个下拉框(必须通知它的处理程序它必须向谁填充其他下拉列表)。

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

所以,我需要以某种方式通知 dropdwon1 它必须填充哪些其他下拉菜单。

谢谢

【问题讨论】:

  • 解释你的问题。你想达到什么目的。如果您可能对它不满意,扩展下拉菜单并不是那么简单,所以也许有更简单的解决方案。如果你解释你想要什么类型的数据等,那么有人可能会指导你。
  • 那么,您需要/想要传递哪些额外的数据或值?我的意思是,页面上的隐藏控件,甚至只是从页面上的控件中获取值都是可能的。因此,与在该事件中获取/获取此类值的代码相比,您可以/将在该事件上发送哪些额外值尚不清楚。现在你可能有一个网格或类似的东西 - 但那将是你遗漏的重要细节

标签: c# asp.net drop-down-menu webforms dropdown


【解决方案1】:

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

dropdownList.SelectedIndexchanged += new EventHandler(MyEventHandler);

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多