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 AddControls
{
	/// <summary>
	/// WebForm1 的摘要说明。
	/// </summary>
	public class WebForm1 : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Button Button1;
		protected System.Web.UI.WebControls.PlaceHolder PlaceHolder1;
		protected System.Web.UI.WebControls.Button Addbtn;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			if (ViewState["AddControl"]!= null)
			{ 
				DropDownList DropDown = new DropDownList(); 				
				PlaceHolder1.Controls.Add(DropDown);
				DropDown.ID="ControlID"; 
			} 
		}

		#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.Addbtn.Click += new System.EventHandler(this.Addbtn_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void Addbtn_Click(object sender, System.EventArgs e)
		{			
			DropDownList DropDown = new DropDownList(); 
			PlaceHolder1.Controls.Clear(); 
			PlaceHolder1.Controls.Add(DropDown); 
			DropDown.ID="ControlID"; 
			DropDown.Width=200;
			DropDown.Items.Add(new ListItem("北京","0"));
			DropDown.Items.Add(new ListItem("上海","1"));
			DropDown.Items.Add(new ListItem("河北","2"));
			ViewState["AddControl"] = true; 
		}
	}
}
