![]() |
|
首页│注册│帮助 | |||
相关问题
| • | [求助]怎么加密ASP的数据 |
| • | 请教用C语言如何实现JPG文件的复制! |
| • | 实现动态圆圈滚动? |
| • | 一个哲学博士与扫黄干警的精彩对话 |
| • | [求助]怎么计算程序运行的时间?急 |
| • | [求助]神经网络的相关资料 |
| • | 一步一步玩转代理服务器 |
| • | 急!!!急!!!急!!! |
待解决
DropDownlist的SelectedIndexChanged事件不起作用
<P>DropDownlist的SelectedIndexChanged事件不起作用:用panel做用户注册页面,每点一次下一步,前一个panel隐藏,后一个panel显示,其中一个panel里面有DropDownlist,比如我现在要绑定省和市的关联,我在省(dropdownlist1)的SelectedIndexChanged事件当中写如下代码: <BR> private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)<BR> {<BR> SqlConnection con=DB.createConnection();<BR> con.Open();<BR> SqlCommand cmdCity=new SqlCommand("select * from city where pID="+this.DropDownList1.SelectedValue,con);<BR> SqlDataReader sdrCity=cmdCity.ExecuteReader();<BR> this.DropDownList2.DataSource=sdrCity;<BR> this.DropDownList2.DataTextField="cName";<BR> this.DropDownList2.DataValueField="cID";<BR> this.DropDownList2.DataBind();<BR> sdrCity.Close();<BR> con.Close();<BR> }<BR>但是在我切换省的时候,市里面是没有变的。我把这些代码换成Response.write("随便写的东西");他也是没有输出。<BR><BR>但是在pageload事件中做的绑定就好使!能够对应<BR> private void Page_Load(object sender, System.EventArgs e)<BR> {<BR> if(!this.IsPostBack)<BR> {<BR><BR> SqlConnection con=DB.createConnection();<BR> con.Open();<BR>//绑定省(dropdownlist1)<BR> SqlCommand cmd=new SqlCommand("select * from province",con);<BR> SqlDataReader sdr=cmd.ExecuteReader();<BR> this.DropDownList1.DataSource=sdr;<BR> this.DropDownList1.DataTextField="pName";<BR> this.DropDownList1.DataValueField="pID";<BR> this.DropDownList1.DataBind();<BR> sdr.Close();<BR>//绑定市(dropdownlist2)</P><P> SqlCommand cmdCity=new SqlCommand("select * from city where pID="+this.DropDownList1.SelectedValue,con);<BR> SqlDataReader sdrCity=cmdCity.ExecuteReader();<BR> this.DropDownList2.DataSource=sdrCity;<BR> this.DropDownList2.DataTextField="cName";<BR> this.DropDownList2.DataValueField="cID";<BR> this.DropDownList2.DataBind();<BR> sdrCity.Close();</P>
<P> con.Close(); <BR> }<BR><BR>注:SelectedIndexChanged一直就没有反应!我不知道问题出在哪里,和Panel有关系吗?如果有,我应该怎么做才行,如果没有关系,问题应该出在哪里呢??<BR><BR>我没有地方可问,就拜托走过路过的师父们了!!</P>
提问者:叶底蝉 2006-06-09 17:49:00
答复
<P>nic的做法是正确的,如果只是做省市的联动的话,最好不要用这种办法,因为这样会很频繁的与服务器之间交互信息,增加服务器负担。只要用javascript就可以实现了,在js版里有很多这样的例子,你可以去看一下。</P>
回答者:小笨笨 -
2006-06-14 08:29:00
onSelectedIndexChanged="DropDownList1_SelectedIndexChanged"<BR>autoPostBack="true"<BR>点击的时候注意观察页面是否有回发的现象
回答者:nic -
2006-06-13 17:05:00
<P>改了,不起作用!</P>
回答者:叶底蝉 -
2006-06-13 14:10:00
dropdownlist1:autoPostBack="true"
回答者:nic -
2006-06-11 22:49:00
<P>过了一天了,怎么没人回复呢~第一次发帖就没人理[em06]</P>
回答者:叶底蝉 -
2006-06-10 13:54:00

