asp.NET省市聯動菜單

 所在省市:<asp:DropDownList ID="ddlProvince" runat="server" AutoPostBack="true"                   OnSelectedIndexChanged="ddlProvince_SelectedIndexChanged"></asp:DropDownList>
           <asp:DropDownList ID="ddlCity" runat="server"></asp:DropDownList>
---------------------------------------------------------------------------------------
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                dataBindToProv();              
                   SqlDataReader sdr = ADRelease.BLL.Enterprise.GetEnterpriseInfo(EnterpriseID);
                    if (sdr.Read())
                    {
                        tbWebName.Text = sdr["WebName"].ToString();
                        tbWebIntro.Text = sdr["WebIntro"].ToString();
                        tbMainBusiness.Text = sdr["MainBusiness"].ToString();
                        tbDomainName.Text = sdr["DomainName"].ToString();
                        tbContactMan.Text = sdr["ContactMan"].ToString();
                        tbContactPhone.Text = sdr["ContactPhone"].ToString();
                        tbFaxNumber.Text = sdr["FaxNumber"].ToString();
                        tbEmail.Text = sdr["Email"].ToString();
                        ddlProvince.SelectedIndex = ddlProvince.Items.IndexOf(ddlProvince.Items.FindByValue(Convert.ToString(sdr["ProvinceID"])));
                        //关键下面两句
                        dataBindToCity();
                        ddlCity.SelectedItem.Text = sdr["City"].ToString();   
               
                        imgLogo.ImageUrl = "../images/logoUpLoad/" + sdr["logo"].ToString();
                        lblPath.Text = sdr["logo"].ToString();
                    }
                    sdr.Close();                   
            }        
           
        }
        //绑定省的下拉
        public void dataBindToProv()
        {
            SqlDataReader sdr1 = ADRelease.BLL.Enterprise.GetProvinceInfo();          
             this.ddlProvince.DataSource = sdr1;
            this.ddlProvince.DataTextField = "ProvinceName";
             this.ddlProvince.DataValueField = "ProvinceID";
             this.ddlProvince.DataBind();
             sdr1.Close();
        }
        //绑定城市下拉
        public void dataBindToCity()
        {
            SqlDataReader sdr2 = ADRelease.BLL.Enterprise.GetCityInfo(int.Parse(this.ddlProvince.SelectedValue.ToString()));
            this.ddlCity.DataSource = sdr2;
           this.ddlCity.DataTextField = "CityName";
            this.ddlCity.DataValueField = "CityID";
            this.ddlCity.DataBind();
            sdr2.Close();
        }

        protected void ddlProvince_SelectedIndexChanged(object sender, EventArgs e)
        {
            dataBindToCity();
        }    

 

posted @ 2010-07-28 10:57  你妹的sb  阅读(457)  评论(1编辑  收藏  举报
百度一下