直接绑定
但是要指定 dropdownlist的text和value 分别为 hashtable的 key和value
Hashtable ht = new Hashtable();
for(int i=0; i<10; i++)
{
ht.Add(i+1,"Item"+1);
}
this.DropDownList1.DataSource = ht;
this.DropDownList1.DataTextField = "key";
this.DropDownList1.DataValueField = "value";
this.DropDownList1.DataBind();
// Put user code to initialize the page here
}
我现在用一个datadownlist控件绑定一个hashtable,为什么在down控件中绑定hashtable的时候项目不是顺序的,而是无顺序的呢?
怎么解决这个问题呀?
把HashTable换成SortedList试试,SortedList是HashTable和Array的混合,既有HashTable的功能,也有ArrayList的排序功能
用arraylist,怎样才能同时确定key又确定value啊??????
ArrayList al=new ArrayList();
al.Add(new ListItem("--请选择--","0"));
al.Add(new ListItem("综合新闻","1"));
......
L_flags.DataSource=al;
this.DropDownList1.DataSource=al;
this.DropDownList1.DataTextField="Text";
this.DropDownList1.DataValueField="Value";
this.DropDownList1.DataBind();