DropDownList的问题
比如DropDownList的Item里面有三个值"lihai","wanghua","liuli" 这四个值,我想从一个页面传一个name=“wanghua”的值,在DropDownList这个页面的item的值"wanghua"就排在最上面,请问各位这个该怎么去实现?谢谢大家!
[解决办法]
选中就好了。
用后台代码:
DropDownList1.SelectedIndex = DropDownList1.Items.IndexOf(DropDownList1.Items.FindByValue("wanghua"))
如果一定要排在上面,如果是我我就这么写:
Dim i as integer=DropDownList1.Items.IndexOf(DropDownList1.Items.FindByValue("wanghua"))
DropDownList1.Items.RemoveAt(i)
DropDownlist1.Items.Insert(0,new ListItem("wanghua","wanghua")
[解决办法]
帮顶后 先找到"wanghua",把这个ItemRemove掉 然后Insert(0,"wanghua")
[解决办法]
如果是写死的话,有一个笨方法供参考:
DropDownList1.Items.Remove(DropDownList1.Items.FindByText("wanghua"));
DropDownList1.Items.Insert(0,new ListItem("wanghua","wanghua"));
DropDownList.SelectValue=wanghua;
[解决办法]
同4楼
drop1.Items.Remove(item);
drop1.Items.Insert(0,item);
[解决办法]
Dim V as string="wanghua"'从数据库读值。自己读。
Dim T as String="wanghua"
Dim i as integer=DropDownList1.Items.IndexOf(DropDownList1.Items.FindByValue(V))
DropDownList1.Items.RemoveAt(i)
DropDownlist1.Items.Insert(0,new ListItem(T,V)
DropDownlist1.SelectedValue="wanghua"