山本

导航

三级联动方法一

 public partial class WebForm2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                LoadProvince();
            }
        }
        /// <summary>
        /// 省份
        /// </summary>
        public void LoadProvince()
        {
            BLL.province bpro = new BLL.province();
            DataTable dt = bpro.GetList("").Tables[0];
            this.ddlProvince.DataSource = dt;
            this.ddlProvince.DataTextField = "provincename";
            this.ddlProvince.DataValueField = "provinceID";
            this.ddlProvince.DataBind();
        }
        /// <summary>
        /// 城市
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ddlProvince_SelectedIndexChanged(object sender, EventArgs e)
        {
            if(this.ddlCity.Items.Count>0)
            {
                this.ddlCity.Items.Clear();
            }
            BLL.city bcity = new BLL.city();
            string cityid = ddlProvince.SelectedItem.Value;
            DataTable dt=bcity.GetList("father='"+cityid+"'").Tables[0];
            this.ddlCity.DataSource = dt;
            this.ddlCity.DataTextField = "cityname";
            this.ddlCity.DataValueField = "cityID";
            this.ddlCity.DataBind();

            string aid = dt.Rows[0]["cityID"].ToString();
            BLL.area ba = new BLL.area();
            DataTable ddt=ba.GetList("father='"+aid+"'").Tables[0];
            this.ddlArea.DataSource = ddt;
            this.ddlArea.DataTextField = "areaname";
            this.ddlArea.DataValueField = "areaID";
            this.ddlArea.DataBind();
        }
        /// <summary>
        /// 县、地区
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ddlCity_SelectedIndexChanged(object sender, EventArgs e)
        {
            BLL.area ba = new BLL.area();
            int areaid=Convert.ToInt32(this.ddlCity.SelectedValue);
            DataTable ddt = ba.GetList("father='" + areaid + "'").Tables[0];
            this.ddlArea.DataSource = ddt;
            this.ddlArea.DataTextField = "areaname";
            this.ddlArea.DataValueField = "areaID";
            this.ddlArea.DataBind();
        }
    }

posted on 2013-05-31 00:04  高级菜鸟  阅读(250)  评论(1编辑  收藏  举报