省市互连

末鹿安然 提交于 2019-12-18 09:25:40

 所在省市:<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();
        }    

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!