1. 程式人生 > >使用dropdownlist的繫結_實現省市列表級聯

使用dropdownlist的繫結_實現省市列表級聯

 protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string sql = "select * from province";
                DataTable dt = SQLHelper.ExecuteDataTable(sql);

                this.DropDownListProvince.DataSource = dt;
                this.DropDownListProvince.DataValueField = "PId";
                this.DropDownListProvince.DataTextField = "Provinces";
                this.DropDownListProvince.DataBind();


            }
        }


        protected void DropDownListProvince_SelectedIndexChanged(object sender, EventArgs e)
        {
            DropDownListCity.Items.Clear();
            int dr =int.Parse(DropDownListProvince.SelectedValue); 
            string sql="select * from city where
[email protected]
";  
            SqlParameter[] pms = new SqlParameter[] { new SqlParameter("@pid", dr) };
            DataTable dt=SQLHelper.ExecuteDataTable(sql,pms);

            this.DropDownListCity.DataSource = dt;
            this.DropDownListCity.DataValueField = "CId";
            this.DropDownListCity.DataTextField = "Citys";
            this.DropDownListCity.DataBind();
        }