1. using System; 
  2. using System.Configuration; 
  3. using System.Data; 
  4. using System.Linq; 
  5. using System.Web; 
  6. using System.Web.Security; 
  7. using System.Web.UI; 
  8. using System.Web.UI.HtmlControls; 
  9. using System.Web.UI.WebControls; 
  10. using System.Web.UI.WebControls.WebParts; 
  11. using System.Xml.Linq; 
  12. using System.Collections; 
  13. public partial class _Default : System.Web.UI.Page 
  14.     protected void Page_Load(object sender, EventArgs e) 
  15.     { 
  16.         if (!IsPostBack) 
  17.             DDLDatabind(); 
  18.     } 
  19.     protected void DDLDatabind() 
  20.     { 
  21.         Hashtable ht = new Hashtable(); 
  22.         ht.Add("1""高数"); 
  23.         ht.Add("2""代数"); 
  24.         ht.Add("3""英语"); 
  25.         ht.Add("4""政治"); 
  26.         ht.Add("5""英语"); 
  27.         DropDownList1.DataSource = ht; 
  28.         DropDownList1.DataTextField = "Value"
  29.         DropDownList1.DataValueField = "Key"
  30.         DropDownList1.DataBind(); 
  31.     } 
  32.  
  33. using System; 
  34. using System.Collections; 
  35. using System.Linq; 
  36. using System.Text; 
  37.  
  38. namespace ConsoleApplication1 
  39.     class Program 
  40.     { 
  41.         static void Main(string[] args) 
  42.         { 
  43.             Hashtable ht = new Hashtable(); 
  44.             ht.Add("2""代数"); 
  45.             ht.Add("1""高数"); 
  46.             ht.Add("3""英语"); 
  47.             ht.Add("4""政治"); 
  48.             ht.Add("5""英语"); 
  49.             ArrayList list = new ArrayList(ht.Keys); 
  50.             list.Sort(); 
  51.             System.Console.WriteLine("Hashtable:"); 
  52.             foreach (string key in list) 
  53.             { 
  54.                 System.Console.WriteLine(key+"     "+ht[key]); 
  55.             } 
  56.             System.Console.ReadLine(); 
  57.         } 
  58.     }