今天遇到一个问题,就是我有一个ListBox需要帮定数据,但数据源是Hashtable,但是要求绑定的数据是排好序的,google了一下,找到一种利用ArrayList的Sort方法来实现的方法。

下面是简单代码示意:

Hashtable ht = new Hashtable();
ht=getHTdata();  //得到数据
ArrayList al = new ArrayList(ht.Keys);
al.Sort();
for (int i = 0; i < al.Count; i++)
{
   ListItem lt = new ListItem(ht[al[i].ToString()].ToString(), al[i].ToString());
   ListBox1.Items.Add(lt);
}
ListBox1.DataBind();

当然ListBox也可以换成其他的控件,比如:DropDownList等

相关文章:

  • 2022-12-23
  • 2021-05-26
  • 2021-08-13
  • 2022-12-23
  • 2022-12-23
  • 2021-09-29
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-29
  • 2021-06-18
  • 2022-12-23
  • 2021-12-06
  • 2022-12-23
相关资源
相似解决方案