我在执行此操作时遇到了很多问题,因此我在页面上有2个下拉菜单,而第一个我想先隐藏。在第二个下拉列表(任何选择)中做出选择之后,我希望第三个下拉列表及其标签变为可见。它们都连接到数据库。我已经以一种简单的方式重新创建了代码的这一方面,以提供视觉效果。
我已在网上搜索以寻求帮助。我是.NET的新手,并且从未使用过jquery或ajax,如果可能的话,我只想在C#中使用它。如果您建议使用jQuery,请详细解释。此时,CS页面几乎为空。任何帮助表示赞赏。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Dropdowns</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="ddlManu" runat="server" AutoPostBack="True"
DataSourceID="SqlDataSource1" DataTextField="Field1" DataValueField="ID" >
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"
SelectCommand="SELECT [Version] FROM [ProductVersion]"
DataSourceMode="DataReader">
</asp:SqlDataSource>
<asp:DropDownList ID="ddlProduct" runat="server"
DataSourceID="SqlDataSource2" DataTextField="Field1" DataValueField="ID"
AutoPostBack="True" >
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>"
ProviderName="<%$ ConnectionStrings:ConnectionString2.ProviderName %>"
SelectCommand="SELECT [ID], [Field1], [Field2],[FKID] FROM [MSProducts]
WHERE FKID = @ID" DataSourceMode="DataReader">
<SelectParameters>
<asp:ControlParameter ControlID="ddlManu" Name="ID"
PropertyName="SelectedValue" DefaultValue="" />
</SelectParameters>
</asp:SqlDataSource>
<br />
<asp:Label ID="Label1" runat="server" Text="Category1:"></asp:Label>
<asp:DropDownList ID="ddlPop" runat="server" DataSourceID="SqlDataSource1">
</asp:DropDownList>
<br />
<br />
<br />
<br />
<br />
<br />
</form>
</body>
</html>
最佳答案
首先,将第三个dd设置为visible false:
<asp:DropDownList ID="ddlPop" runat="server" Visible="false"></asp:DropDownList>
然后,在第二个dd的OnSelectedIndexChanged方法上,执行以下操作:
protected void ddlProduct_SelectedIndexChanged(object sender, EventArgs e)
{
ddlPop.Visible = true;
}
我创建了一个小样本来使用jquery做同样的事情。
但请注意,为使此方法生效,您需要为控件禁用回发。
http://jsfiddle.net/Gys5Y/1/
关于c# - 在asp.net的另一个下拉框中进行选择后,如何显示隐藏的下拉框?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19009677/