change
for i=0 to ListBox1.Items.Count-1
===>
for i=ListBox1.Items.Count-1 to 0 step -1

解决方案 »

  1.   

    你在循环体内改变了ListBox1,必须做些特殊处理
    ListBox1.Items.Remove(ListBox1.Items(i))
    后将i减1或者while (ListBox1.SelectedIndex>-1)
    {
    ListBox2.Items.Add(ListBox1.SelectedItem);
    ListBox1.Items.Remove(ListBox1.SelectedItem);
    }
    //多选的时候SelectedItem是第一个选中项,逐个操作就可以了
      

  2.   

    多谢二位,还有一点不明,为什么用c#这样写就没有错误?
    <%@ Page Language="C#" %>
    <html>
    <head>
       <script runat="server">
          void SubmitBtn_Click(Object sender, EventArgs e) 
          {
             for(int i=0;i<ListBox1.Items.Count;i++){
              if(ListBox1.Items[i].Selected){
              ListBox2.Items.Add(ListBox1.Items[i]);
              ListBox2.SelectedIndex=-1;
              ListBox1.Items.Remove(ListBox1.Items[i]);
              }
            }
            
          }
       </script>