How to filter dropdown list values ​​by another dropdown list in ASP.NET, C #

I have a simple question about filters. I have 4 dropdowns that filter data in my web application from a MySQL database table. The first drop-down list is already selected, showing only one project_id, but the rest of the drop-down lists show all possible values ​​from the database - this is what I have done so far.

But I want to display only data values ​​for the selected specific project.

It uses ASP.NET 4.0, C # and the MySQL database. Any help would be appreciated. Thanks

+6
source share
2 answers

Browse through the following links to populate the cascading drop-down list.

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

the code:

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

// Code for protected void Page_Load (object sender, EventArgs e) {if (! IsPostBack) {// your code to bind the first drop-down list down

  } } 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 } } 
+6
source

Filter the second drop down data source with the selected value of the first drop-down list

see this article http://www.asp.net/data-access/tutorials/master-detail-filtering-with-two-dropdownlists-

+3
source

Source: https://habr.com/ru/post/901419/


All Articles