日期:2014-05-18 浏览次数:20529 次
protected void Page_Load(object sender, EventArgs e) { BindDropDownList1(); BindDropDownList2(DropDownList1.SelectedValue); } private void BindDropDownList1() { IList<Class1> list = BL.Instance.GetDropDownList1DataSource(); DropDownList1.Items.Add(new ListItem("---请选择---", "-1")); foreach (Class1 class in list) { DropDownList1.Items.Add(new ListItem(class1.text, class.value)); } } private void BindDropDownList2(int value) { DropDownList2.Items.Clear(); DropDownList2.Items.Add(new ListItem("---请选择---", "-1")); if (value > 0) { IList<Class2> list = BL.Instance.GetDropDownList2DataSource(value); foreach (Class2 class in list) { DropDownList2.Items.Add(new ListItem(class.text, class.value)); } } } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { BindDropDownList2(BindDropDownList1.SelectedValue); }
------解决方案--------------------
再在Page_Load里面要加一个if (!IsPostBack) 哈.
------解决方案--------------------
参考:
http://blog.csdn.net/insus/archive/2007/11/11/1878690.aspx
http://download.csdn.net/source/282546