using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace ApplyDropDownList
{
	/// <summary>
	/// WebForm1 的摘要说明。
	/// </summary>
	public class WebForm1 : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.DropDownList DropDown1;
		protected System.Web.UI.WebControls.Button Remove;
		protected System.Web.UI.WebControls.Label Label1;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			if(!IsPostBack)
			{
				DropDown1.Items.Add( new ListItem("北京","1"));
				DropDown1.Items.Add( new ListItem("上海","2"));
				DropDown1.Items.Add( new ListItem("唐山","3"));
				DropDown1.Items.Add( new ListItem("深圳","4"));
			}
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN：该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.DropDown1.SelectedIndexChanged += new System.EventHandler(this.DropDown1_SelectedIndexChanged);
			this.Remove.Click += new System.EventHandler(this.Remove_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void DropDown1_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			int Index = DropDown1.SelectedIndex ;
			String text = DropDown1.SelectedItem.Text;
			Label1.Text = Index.ToString() + text;
		}

		private void Remove_Click(object sender, System.EventArgs e)
		{
			if(DropDown1.Items.Count > 1)
			{
				ListItem Item = DropDown1.SelectedItem;
				DropDown1.Items.Remove(Item);
				String val = DropDown1.SelectedItem.Value ;
				String text = DropDown1.SelectedItem.Text;
				Label1.Text = val + text;
			} 
			else 
			{
				DropDown1.Items.Clear();
				Label1.Text = "";
			}
		}
	}
}
