在ascx页面自定义无限极下拉菜单,数据来自DB.类似于国家、省、市联动。
1、下面这段代码第一个下拉框触发事件,第二个就触发了,什么原因。
protected void Page_Load(object sender, EventArgs e) { DropDownList myDdl = new DropDownList(); myDdl.Items.Add("Test"); myDdl.Items.Add("Test2"); myDdl.AutoPostBack = true; myDdl.SelectedIndexChanged += new EventHandler(SelectedIndexChanged); if (!this.Page.Form.Controls.Contains(myDdl)) { this.Page.Form.Controls.Add(myDdl); } } void SelectedIndexChanged(object sender, EventArgs e) { DropDownList ddl = sender as DropDownList; DropDownList myDdl1 = new DropDownList(); myDdl1.Items.Add("Test3"); myDdl1.Items.Add("Test4"); myDdl1.AutoPostBack = true; myDdl1.SelectedIndexChanged += new EventHandler(SelectedIndexChanged); this.Page.Form.Controls.Add(myDdl1); }
2、比如我现在已经加载8个下拉框,点击第二个下拉框,那么后面的下拉框要全部remove,第三个根据数据判断是否加载,这个怎么实现?