老问题把ListItem lim =new ListItem ("sdfdsfd","0");
dd.Items.Add (lim);

ListItem lim1 =new ListItem ("123","1");
dd.Items.Add (lim1);
ListItem lim2 =new ListItem ("ee","0");
dd1.Items.Add (lim1);
ListItem lim3 =new ListItem ("ww","1");
dd1.Items.Add (lim);
}放在if(!this.Page.IsPostBack){}里面

解决方案 »

  1.   


    foreach(ListItem lim in dd1.Items )
       dd1.Items.Remove (lim);===》this.dd1.Items.Clear();
      

  2.   

    if(!IsPostBack)
    {Add[Items]
    }
      

  3.   

    可以用Remove但clear方法就能达到你的要求
      

  4.   

    用clear可以但用remove就出同样的错误
      

  5.   

    if(!IsPostBack)
    {
       }
      

  6.   

    certainly, this method is wrong:
    foreach(ListItem lim in dd1.Items )
    dd1.Items.Remove (lim);because if you delete one item ,the dropdownlist's item collection has been changed. actually, in foreach sentence the datacollection should be static and fixed.
      

  7.   

    wacle([Smile!]) 说得对
    其实这个问题在datatable,等都是样的,你也可以这样
    for(int i=0;i<ddl.Items.Count;i++)
    {
    ddl.Items.Remove(ddl.Items[0]);
    }
    当然在本题中还是用ddl.clear好