如何吧一个Dropdownlist选中的值传到另一个dropdownlist?

来源:百度知道 编辑:UC知道 时间:2024/06/14 19:40:38
例如常见的注册时选择所在地的那种样式,例如第一个选了广西,第二个出现广西的各个城市名,用代码实现,而不是控件!急!!!
一个超无奈的问题,我通过定义第一个Dropdownlist的选择值string aa =(String) DropDownList1.SelectedValue;然后dropdownlist2的select语句为select distinct city from diming where sheng='aa',按理说这样能行啊,可是dropdownlist2的下拉框仍然没有任何数据

这样行:
string aa =(String) DropDownList1.SelectedValue;然后dropdownlist2的select语句为select distinct city from diming where sheng='"+aa+"'
你得把aa作为参数传给select语句

string provice=DropDownList1.SelectedValue;
然后在DropDownList2上添加一个数据绑定控件如ObjectDataSouce等,在选定数据源时写Select distinct city from diming where sheng=@provice,其中参数选择来自控件Control也就是DropDownList1啦,如此就OK了,试试看啦!应该可以!

当第一个dropdownlist发生变话的时候 触发selectchanged事件
在这个事件中绑定第二个dropdownlist就这么简单

这么晚起来撒尿咯,随便帮你解决这个问题。
希望我白天睡觉的时候你能把问题解决,随便跟我说声谢谢,我就睡得好香咯。

你在绑定数据后加上下面三句代码看看,我估计是这的问题。

DropDownList2.DataTextField = "city";
DropDownList2.DataValueField = "city";
DropDownList2.DataBind();

"select distinct city from diming where sheng='"+aa+"'"