C# ASP.Net 中如何使用ajax制作两个下拉框的无刷新,联动连接数据库的
展开全部
把 dropdownlist 控件 放进 updatepanel
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged">
</asp:DropDownList>
</asp:UpdatePanel>
在.cs中编写响应选择事件处理,绑定数据源等
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string strupclassID = DropDownList1.SelectedItem.Value.ToString();
DropDownList2.Visible = true;
ddl_databindforLastclass(strupclassID);
.........
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
string strupclassid = DropDownList2.SelectedItem.Value.ToString();
..........
}
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged">
</asp:DropDownList>
</asp:UpdatePanel>
在.cs中编写响应选择事件处理,绑定数据源等
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string strupclassID = DropDownList1.SelectedItem.Value.ToString();
DropDownList2.Visible = true;
ddl_databindforLastclass(strupclassID);
.........
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
string strupclassid = DropDownList2.SelectedItem.Value.ToString();
..........
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询