if (!this.IsPostBack)
{
//绑定省
SqlConnection con = DB.creatConnection();
con.Open();
SqlCommand cmd = new SqlCommand("select *from province", con);
SqlDataReader sdr = cmd.ExecuteReader();
this.ddlprovince.DataSource = sdr;
this.ddlprovince.DataTextField = "proname";
this.ddlprovince.DataBind();
sdr.Close();
// 绑定市 SqlCommand cmdcity = new SqlCommand("select *from city where proid="+this.ddlprovince.SelectedValue, con);
sdr = cmdcity.ExecuteReader();
this.ddlcity.DataSource = sdr;
this.ddlcity.DataTextField = "cityname";
this.ddlcity.DataValueField = "cityid";
this.ddlcity.DataBind();
sdr.Close();
con.Close();
}
有什么问题啊,他显示的是“北京'无效
{
//绑定省
SqlConnection con = DB.creatConnection();
con.Open();
SqlCommand cmd = new SqlCommand("select *from province", con);
SqlDataReader sdr = cmd.ExecuteReader();
this.ddlprovince.DataSource = sdr;
this.ddlprovince.DataTextField = "proname";
this.ddlprovince.DataBind();
sdr.Close();
// 绑定市 SqlCommand cmdcity = new SqlCommand("select *from city where proid="+this.ddlprovince.SelectedValue, con);
sdr = cmdcity.ExecuteReader();
this.ddlcity.DataSource = sdr;
this.ddlcity.DataTextField = "cityname";
this.ddlcity.DataValueField = "cityid";
this.ddlcity.DataBind();
sdr.Close();
con.Close();
}
有什么问题啊,他显示的是“北京'无效
if (!this.IsPostBack)
{
//绑定省
SqlConnection con = DB.creatConnection();
con.Open();
SqlCommand cmd = new SqlCommand("select *from province", con);
SqlDataReader sdr = cmd.ExecuteReader();
this.ddlprovince.DataSource = sdr;
this.ddlprovince.DataTextField = "proname";
this.ddlprovince.DataValueField = "proid";//加上这行 省一定有id 字段名称你自己对应
this.ddlprovince.DataBind();
sdr.Close();
// 绑定市 SqlCommand cmdcity = new SqlCommand("select * from city where proid="+this.ddlprovince.SelectedValue, con);
sdr = cmdcity.ExecuteReader();
this.ddlcity.DataSource = sdr;
this.ddlcity.DataTextField = "cityname";
this.ddlcity.DataValueField = "cityid";
this.ddlcity.DataBind();
sdr.Close();
con.Close();
}