用DropDownList实现的省市级三级联动

这是一个用DropDownList 实现的省市级三级联动,记录一下········


 <asp:ScriptManager ID="ScriptManager1" runat="server">/asp:ScriptManager>

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
                         <ContentTemplate>
<p><span class="redcolor">* </span>选择地区:
                         <asp:DropDownList ID="ProvinceSelect" AutoPostBack="True"  runat="server" OnSelectedIndexChanged="GetCityName_onClick">
</asp:DropDownList> <asp:DropDownList runat="server" ID="CitySelect" AutoPostBack="True" OnSelectedIndexChanged="Getcounty_OnClick"  >
</asp:DropDownList> <asp:DropDownList   AutoPostBack="True" runat="server" ID="County">
</asp:DropDownList>
</p>
                       </ContentTemplate>
                         <Triggers>
                            <asp:AsyncPostBackTrigger ControlID="ProvinceSelect" EventName="SelectedIndexChanged" />
                        </Triggers>
</asp:UpdatePanel>

后台代码:

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ProvinceSelect.DataSource = BFL.GetPrivoces();
ProvinceSelect.DataTextField = "RegionName";
ProvinceSelect.DataValueField = "RegionId";
ProvinceSelect.DataBind();
ProvinceSelect.Items.Insert(0, new ListItem("请选择", string.Empty));
CitySelect.Items.Insert(0, new ListItem("请选择", string.Empty));
County.Items.Insert(0, new ListItem("请选择", string.Empty));
}
}
        #region 省市县数据绑定
        //市级绑定
        public void GetCityName_onClick(object sender, EventArgs e)
        {
            CitySelect.DataSource = BFL.GetCitys(int.Parse(ProvinceSelect.SelectedItem.Value));
            CitySelect.DataTextField = "RegionName";
            CitySelect.DataValueField = "RegionId";
            CitySelect.DataBind();
            County.Items.Insert(0, new ListItem("请选择", string.Empty));
        }
        //县级绑定
        public void Getcounty_OnClick(object sender, EventArgs e)
        {
            County.DataSource = BFL.GetCitys(int.Parse(CitySelect.SelectedItem.Value));
            County.DataTextField = "RegionName";
            County.DataValueField = "RegionId";
            County.DataBind();
            County.Items.Insert(0,new ListItem("请选择",string.Empty));
        }
        #endregion
上一篇:关于Yahoo十四条军规与前端性能优化


下一篇:FPGA---Basys3(实验内容汇总贴)