DropDownlist的SelectedIndexChanged事件不起作用:用panel做用户注册页面,每点一次下一步,前一个panel隐藏,后一个panel显示,其中一个panel里面有DropDownlist,比如我现在要绑定省和市的关联,我在省(dropdownlist1)的SelectedIndexChanged事件当中写如下代码:
private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
SqlConnection con=DB.createConnection();
con.Open();
SqlCommand cmdCity=new SqlCommand("select * from city where pID="+this.DropDownList1.SelectedValue,con);
SqlDataReader sdrCity=cmdCity.ExecuteReader();
this.DropDownList2.DataSource=sdrCity;
this.DropDownList2.DataTextField="cName";
this.DropDownList2.DataValueField="cID";
this.DropDownList2.DataBind();
sdrCity.Close();
con.Close();
}
但是在我切换省的时候,市里面是没有变的。我把这些代码换成Response.write("随便写的东西");他也是没有输出。
但是在pageload事件中做的绑定就好使!能够对应
private void Page_Load(object sender, System.EventArgs e)
{
if(!this.IsPostBack)
{
SqlConnection con=DB.createConnection();
con.Open();
//绑定省(dropdownlist1)
SqlCommand cmd=new SqlCommand("select * from province",con);
SqlDataReader sdr=cmd.ExecuteReader();
this.DropDownList1.DataSource=sdr;
this.DropDownList1.DataTextField="pName";
this.DropDownList1.DataValueField="pID";
this.DropDownList1.DataBind();
sdr.Close();
//绑定市(dropdownlist2)
SqlCommand cmdCity=new SqlCommand("select * from city where pID="+this.DropDownList1.SelectedValue,con);
SqlDataReader sdrCity=cmdCity.ExecuteReader();
this.DropDownList2.DataSource=sdrCity;
this.DropDownList2.DataTextField="cName";
this.DropDownList2.DataValueField="cID";
this.DropDownList2.DataBind();
sdrCity.Close();
con.Close();
}
注:SelectedIndexChanged一直就没有反应!我不知道问题出在哪里,和Panel有关系吗?如果有,我应该怎么做才行,如果没有关系,问题应该出在哪里呢??
我没有地方可问,就拜托走过路过的师父们了!!