当前位置: 代码迷 >> ASP.NET >> asp.net 中 listbox中与此同时删除多项
  详细解决方案

asp.net 中 listbox中与此同时删除多项

热度:7299   发布时间:2013-02-26 00:00:00.0
asp.net 中 listbox中同时删除多项

帮看看:  
  foreach   (ListItem   aa   in   ListBox1.Items)
                {
                        if   (aa.Selected   ==   true)
                        {
                                this.ListBox1.Items.Remove(aa.Text);
                        }
                }
  报错   :集合已修改;可能无法执行枚举操作。

------解决方案--------------------------------------------------------
别用foreach ,就用for循环,从后向前删
------解决方案--------------------------------------------------------
因为按顺序删除之后ListBox1.Items中的内容已经变化,只能按索引倒着删。