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

前端之家收集整理的这篇文章主要介绍了如何通过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

码:

  1. <table>
  2. <tr>
  3. <td>First</td>
  4. <td><asp:DropDownList ID="DDLFirst" runat="server" AutoPostBack="true"
  5. onselectedindexchanged="DDLFirst_SelectedIndexChanged"></asp:DropDownList></td>
  6. </tr>
  7. <tr>
  8. <td>Secord</td>
  9. <td><asp:DropDownList ID="DDLSecond" runat="server" AutoPostBack="true"
  10. onselectedindexchanged="DDLSecond_SelectedIndexChanged">
  11. <asp:ListItem Text="Select" Value="Select"></asp:ListItem>
  12. </asp:DropDownList></td>
  13. </tr>
  14. <tr>
  15. <td>Thrid</td>
  16. <td><asp:DropDownList ID="DDLThird" runat="server"><asp:ListItem Text="Select" Value="Select"></asp:ListItem> </asp:DropDownList></td>
  17. </tr>
  18. </table>

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

  1. }
  2. }
  3.  
  4. protected void DDLFirst_SelectedIndexChanged(object sender,EventArgs e)
  5. {
  6. if (DDLFirst.SelectedIndex > 0)
  7. {
  8. string FirstDDLValue = DDLFirst.SelectedItem.Value;
  9. // below your code to get the second drop down list value filtered on first selection
  10.  
  11.  
  12. }
  13.  
  14. }
  15.  
  16. protected void DDLSecond_SelectedIndexChanged(object sender,EventArgs e)
  17. {
  18. if (DDLSecond.SelectedIndex > 0)
  19. {
  20. string SecondDDLValue = DDLSecond.SelectedItem.Value;
  21. // below your code to get the third drop down list value filtered on Second selection
  22.  
  23.  
  24. }
  25. }

猜你在找的asp.Net相关文章