【问题标题】:Pass index from one control to another将索引从一个控件传递到另一个控件
【发布时间】:2011-12-26 19:10:45
【问题描述】:

我在 GridView 中有两个 DropDownList。 DropDownLists 仅在 GridView 处于编辑模式时显示。第一个 DropDownList 已正确填写。基于第一个 DropDownList 中的选择,所选值将作为第二个 DropDownList 查询的输入。我该如何在 C# 中执行此操作?我为第二个 DropDownList 定义什么样的参数? DebtorKey 来自第一个 DropDownList。

第二个 DropDownList 的 ASP 代码

<asp:ObjectDataSource ID="ObjectDataSourceSpokeTo" runat="server" 
    OldValuesParameterFormatString="original_{0}" SelectMethod="GetData" 
    TypeName="ValidationPortal.VerificationDataSetTableAdapters.getSpokeToTableAdapter">
    <SelectParameters>
        <asp:ControlParameter ControlID="GridView1" DefaultValue="0" Name="DebtorKey" 
            PropertyName="SelectedValue" Type="Int32" />
    </SelectParameters>
</asp:ObjectDataSource>

【问题讨论】:

    标签: c# asp.net


    【解决方案1】:

    您正在寻找的是级联下拉菜单。下面是几个要查看的链接,ASP.NET AJAX 有一个版本,JQuery 是我的首选方式,但您必须查看 GridView 中生成的客户端 ID 等内容。

    ASP.NET AJAX Version

    Jquery Version

    【讨论】:

      【解决方案2】:

      在第一个下拉列表的 SelectedIndexChanged 中,您可以实现查询以填充第二个下拉列表。

      protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { // 如果 x 在 dropdown1 中被选中,则填充 dropdown2 }

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-06-26
        • 2012-07-19
        • 1970-01-01
        相关资源
        最近更新 更多