2011-11-14 49 views
6

我有一個關於過濾器的簡單問題。 我有4個下拉列表,它從MySQL數據庫表中過濾我的Web應用程序中的數據。 第一個下拉列表已被選中,只顯示一個project_id,但其他下拉列表顯示數據庫中所有可能的值 - 這是我迄今爲止所做的。如何通過ASP.NET中的另一個下拉列表過濾下拉列表值,c#

但我想只顯示選定的特定項目的數據值。

這是ASP.NET 4.0,C#後面和MySQL數據庫使用。 任何幫助將不勝感激。 感謝

回答

6

退房以下鏈接。

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> 

//後面 保護無效的Page_Load代碼(對象發件人,EventArgs的){ 如果 (的IsPostBack ) {// 你的代碼的首次下降綁定downlist

 } 
    } 

    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 


     } 
    } 
+0

謝謝大家,它確實有幫助。所以我需要的是AJAX ToolKit和CascadignDropDown控件。 – Pepys

+0

是否有另一種方法來做到這一點。沒有AJAX工具包..不知何故,我不爲我工作,我感到困惑..:[ – Pepys

+1

你可以通過回發來完成。當Dropdownlist SelectedIndexChanged事件綁定第二個下拉列表時。並在第二個selectedindexchanged綁定第三下沉列表。 –

相關問題