如何通过 ASP.NET、c# 中的另一个下拉列表过滤下拉列表值 [英] How to filter dropdown list values by another dropdown list in ASP.NET, c#
问题描述
我有一个关于过滤器的简单问题.我有 4 个下拉列表,它们从 MySQL 数据库表中过滤我的 Web 应用程序中的数据.第一个下拉列表已被选中,仅显示一个 project_id,但其他下拉列表显示了数据库中所有可能的值——这是我目前所做的.
I have a simple question about filters. I have 4 dropdown lists which filter the data in my web application from MySQL database table. The first dropdown list is already selected showing only one project_id but the others drop down lists displays all the possible values from the database - this is what I made so far.
但我只想显示所选特定项目的数据值.
But I want to display only the data values for that particular project selected.
它是 ASP.NET 4.0,背后是 C# 和 MySQL 数据库.任何帮助将不胜感激.谢谢
It's ASP.NET 4.0, C# behind and MySQL database used. Any help will be appreciated. Thanks
推荐答案
查看以下链接以填充级联下拉列表.
check out following links for populating 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/文章/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>
//后面的代码protected void Page_Load(object sender, EventArgs e){如果 (!IsPostBack){//绑定第一个下拉列表的代码
// Code behind protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { // your code to bind the first drop 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
}
}
这篇关于如何通过 ASP.NET、c# 中的另一个下拉列表过滤下拉列表值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!