首页 > 其他 > 详细

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

时间:2016-01-09 23:06:14      阅读:393      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!