码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-01-09 23:09:26      阅读:353      评论:0      收藏:0      [点我收藏+]

标签:

这是一个用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

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

标签:

原文地址:http://www.cnblogs.com/huangenai/p/5117404.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!