asp.net_ArraryList,Hashtable,SortedList,Xml文件的排序和绑定控件

1.只绑定一个数的时候:

ArraryList list=new ArraryList();

list.Add("B");

list.Add("A");

list.Add("C");

list.Add("D");

list.Sort();按字母正排序

list.Reverse();反排序

list.TrimToSize();最终尺寸

ddl.DataSource=list;//指定数据源

ddl.DataBind();//绑定

2.绑定两个数时:

 ArrayList list=new ArrayList();


  SortedList list=new SortedList();//或Hashtable list=new Hashtable();
  list.Add("B","banana");
  list.Add("A","Apple");
  list.Add("D","Dog");
  list.Add("C","Cat");

  x_ddl.DataSource=list;
  x_ddl.DataValueField="key";
  x_ddl.DataTextField="value";
  x_ddl.DataBind();

 

3.绑定Xml文件时,用DataSet:

  DataSet list=new DataSet();
  list.ReadXml(MapPath("test.xml"));
 
  x_ddl.DataSource=list;
  x_ddl.DataValueField="value";//绑定值是这里不是key,而是value,切记
  x_ddl.DataTextField="text";
  x_ddl.DataBind();

你可能感兴趣的:(apple,xml,.net,asp.net,asp)