如何在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数据库。
任何帮助将AP preciated。
谢谢
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.
<一个href=\"http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/CascadingDropDown/CascadingDropDown.aspx\" rel=\"nofollow\">http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/CascadingDropDown/CascadingDropDown.aspx
HTTP://www.$c$cproject.com/KB/ ASPNET / CascadingDropDown.aspx
的http://www.aspsnippets.com/Articles/Creating-Cascading-DropDownLists-in-ASP.Net.aspx
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背后
保护无效的Page_Load(对象发件人,EventArgs的发送)
{
如果(!的IsPostBack)
{
//你的code绑定的首次下降downlist
// 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屋!