【问题标题】:calling multiple dropdownlist index change methods within the another ddl index change在另一个 ddl 索引更改中调用多个下拉列表索引更改方法
【发布时间】:2013-12-18 12:05:15
【问题描述】:

我正在使用 Visual Studio 12,使用 c# 在 asp.net 中编码。
我的代码中有 3 个下拉列表,所有这些都由我创建的列表绑定。
关于调用 ddl 的回发值以执行任务的更好方法,我需要一些建议。

选项 1
当用户从下拉列表 3 中选择一个项目时,通过调用该方法将回发值从 Dropdownlist3_SelectedIndexChanged 发送到 dropdownlist2_selectedindexchanged。只有在我拥有两个回发值之后,我才想生成一个图表。不管图表包含什么,也不管下拉列表中的数据是什么。

类似

protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
 // I would like to have the postbackvalue of drop down list 3 here so i can use its value and dropdownlist2's postbackvalue to produce a chart.
}

在下拉列表中3

protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
{
// I would like to call DropDownlist2_SelectedIndexChanged(...) method so I can send the postbackvalue of DDL3 for use in DDL2.
}

选项 2:
定义一个全局变量来存储 Dropdownlist3 的回发值,并在 Dropdownlist2_SelectedIndexChanged 方法中使用该值以供进一步使用,例如生成图表。

我已经阅读了很多关于全局变量的内容,但不了解它们的缺点。

【问题讨论】:

    标签: c# asp.net methods drop-down-menu global-variables


    【解决方案1】:

    我不确定这是否是您所追求的,但也许有第三种方法被调用来处理图表的更新......

    例如

    protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
    {
        BuildChart();
    }
    
    protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
    {
        BuildChart();
    }
    
    private BuildChart()
    {
        var ddl3Value = DropDownList3.SelectedValue;
        var ddl2Value = DropDownList2.SelectedValue;
    
        if(ddl3Value != null && ddl2Value != null)
        {
            //build chart.
        }
    }
    

    【讨论】:

    • 请给我一些时间,我会尽快在我的解决方案上测试它。从外观上看,它会起作用的!你了解全局变量吗?
    • c# 中没有global variables 阅读this
    • here 是关于如何使用可以像“全局变量”一样使用的静态类的更多帮助
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多