【问题标题】:How to filter dropdown list values by another dropdown list in ASP.NET, c#如何通过 ASP.NET 中的另一个下拉列表过滤下拉列表值,c#
【发布时间】:2011-12-28 11:35:49
【问题描述】:

我有一个关于过滤器的简单问题。 我有 4 个下拉列表,它们从 MySQL 数据库表中过滤我的 Web 应用程序中的数据。 第一个下拉列表已被选中,仅显示一个 project_id,但其他下拉列表显示数据库中所有可能的值 - 这是我到目前为止所做的。

但我只想显示所选特定项目的数据值。

它是 ASP.NET 4.0,后面是 C#,使用的是 MySQL 数据库。 任何帮助将不胜感激。 谢谢

【问题讨论】:

    标签: c# mysql asp.net drop-down-menu filter


    【解决方案1】:

    查看以下链接以填充级联下拉列表。

    http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/CascadingDropDown/CascadingDropDown.aspx

    http://www.codeproject.com/KB/aspnet/CascadingDropDown.aspx

    http://www.aspsnippets.com/Articles/Creating-Cascading-DropDownLists-in-ASP.Net.aspx

    代码:

    <table>
        <tr>
            <td>First</td>
            <td><asp:DropDownList ID="DDLFirst" runat="server"  AutoPostBack="true"
                    onselectedindexchanged="DDLFirst_SelectedIndexChanged"></asp:DropDownList></td>
        </tr>
        <tr>
            <td>Secord</td>
            <td><asp:DropDownList ID="DDLSecond" runat="server" AutoPostBack="true"
                    onselectedindexchanged="DDLSecond_SelectedIndexChanged">
                <asp:ListItem Text="Select" Value="Select"></asp:ListItem>    
                </asp:DropDownList></td>
        </tr>
        <tr>
            <td>Thrid</td>
            <td><asp:DropDownList ID="DDLThird" runat="server"><asp:ListItem Text="Select" Value="Select"></asp:ListItem>    </asp:DropDownList></td>
        </tr>
    </table>
    

    // 后面的代码 protected void Page_Load(object sender, EventArgs e) { 如果(!IsPostBack) { // 绑定第一个下拉列表的代码

            }
        }
    
        protected void DDLFirst_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (DDLFirst.SelectedIndex > 0)
            {
                string FirstDDLValue = DDLFirst.SelectedItem.Value;
                // below your code to get the second drop down list value filtered on first selection
    
    
            }
    
        }
    
        protected void DDLSecond_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (DDLSecond.SelectedIndex > 0)
            {
                string SecondDDLValue = DDLSecond.SelectedItem.Value;
                // below your code to get the third drop down list value filtered on Second selection
    
    
            }
        }
    

    【讨论】:

    • 谢谢你们,这真的很有帮助。所以我需要的是 AJAX ToolKit 和 CascadignDropDown 控件。
    • 还有其他方法吗?如果没有 AJAX 工具包.. 不知何故我不适合我,我很困惑.. :[
    • 您可以通过回发来完成。当 Dropdownlist SelectedIndexChanged 事件绑定第二个下拉列表。并在第二个 selectedindexchanged 上绑定第三个下拉列表。
    • 你好,Pragnesh。我仍然没有任何成功。你有更多关于如何使用回发和 SelectedIndexChanged 事件的信息吗?
    【解决方案2】:

    使用第一个下拉控件的选定值过滤第二个下拉数据源

    看这篇文章http://www.asp.net/data-access/tutorials/master-detail-filtering-with-two-dropdownlists-

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-03-08
    • 2020-10-18
    • 2015-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多