繁体   English   中英

如何通过ASP.NET中的另一个下拉列表过滤下拉列表值,c#

[英]How to filter dropdown list values by another dropdown list in ASP.NET, c#

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

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

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

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

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>

//隐藏后的代码void Page_Load(object sender,EventArgs e){if(!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


        }
    }

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

请参阅此文章http://www.asp.net/data-access/tutorials/master-detail-filtering-with-two-dropdownlists-

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM