- using System;
- using System.Configuration;
- using System.Data;
- using System.Linq;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.HtmlControls;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Xml.Linq;
- using System.Collections;
- public partial class _Default : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- DDLDatabind();
- }
- protected void DDLDatabind()
- {
- Hashtable ht = new Hashtable();
- ht.Add("1", "高数");
- ht.Add("2", "代数");
- ht.Add("3", "英语");
- ht.Add("4", "政治");
- ht.Add("5", "英语");
- DropDownList1.DataSource = ht;
- DropDownList1.DataTextField = "Value";
- DropDownList1.DataValueField = "Key";
- DropDownList1.DataBind();
- }
- }
- using System;
- using System.Collections;
- using System.Linq;
- using System.Text;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- Hashtable ht = new Hashtable();
- ht.Add("2", "代数");
- ht.Add("1", "高数");
- ht.Add("3", "英语");
- ht.Add("4", "政治");
- ht.Add("5", "英语");
- ArrayList list = new ArrayList(ht.Keys);
- list.Sort();
- System.Console.WriteLine("Hashtable:");
- foreach (string key in list)
- {
- System.Console.WriteLine(key+" "+ht[key]);
- }
- System.Console.ReadLine();
- }
- }
- }