簡體   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