客户端:
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True"
onselectedindexchanged="DropDownList2_SelectedIndexChanged">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList3" runat="server">
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
服务端:
public partial class 三¨y级?联¢a动¡¥ : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DropDownList1.DataSource = ElectronMaster.DBHelper.GetTable("select * from T_System_Province");
DropDownList1.DataTextField = "ProvinceName";
DropDownList1.DataValueField = "ProvinceId";
DropDownList1.DataBind();
DropDownList1.Items.Insert(0,new ListItem("***请选择***"));
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList2.DataSource = ElectronMaster.DBHelper.GetTable("select * from T_System_City where ProvinceId=" + DropDownList1.SelectedItem.Value+ "");
DropDownList2.DataTextField = "CityName";
DropDownList2.DataValueField = "CityId";
DropDownList2.DataBind();
DropDownList2.Items.Insert(0, new ListItem("***请选择***"));
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList3.DataSource = ElectronMaster.DBHelper.GetTable("select * from T_System_Area where CityId=" + DropDownList2.SelectedItem.Value + "");
DropDownList3.DataTextField = "AreaName";
DropDownList3.DataValueField = "AreaId";
DropDownList3.DataBind();
DropDownList3.Items.Insert(0, new ListItem("***请选择***"));
}
}