所在省市:<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();
}
来源:https://www.cnblogs.com/gdjlc/archive/2008/10/07/2086978.html