foreach (DataGridItem gridrow in this.grdPredetermine.Items)
            {
                string paramID = this.grdPredetermine.DataKeys[gridrow.ItemIndex].ToString();
                Label mylblChargeCategoryID = (Label)gridrow.Cells[38].Controls[0].FindControl("lblChargeCategoryID");
                string paramChargeCategoryID = mylblChargeCategoryID.Text;
                string paramProjectID = this.drpProject.SelectedValue;
                int paramFinanceYear = int.Parse(this.drpFinanceYear.SelectedValue);
                int paramFinanceMonth = int.Parse(this.drpFinanceMonth.SelectedValue);
                if (paramID != string.Empty)
                {
                    double paramFirsth = 0.0;
                    double paramLast = 0.0;
                    this.GetValues(gridrow, paramFinanceMonth, ref paramFirsth, ref paramLast);
                    this.UpdateProject(paramID, this.OperatorID, paramFinanceMonth, paramFirsth, paramLast, paramChargeCategoryID, paramProjectID, paramFinanceYear);
                    //break;
                }
                else
                {
                    double paramFirsth = 0;
                    double paramLast = 0;
                    this.GetValues(gridrow, paramFinanceMonth, ref paramFirsth, ref paramLast);
                                   this.AddProject(this.OperatorID, paramChargeCategoryID, paramProjectID, paramFinanceYear, paramFinanceMonth, paramFirsth, paramLast);                }
            }
循环第2次的时候  foreach (DataGridItem gridrow in this.grdPredetermine.Items)
一in这里提示集合已修改;可能无法执行枚举操作

解决方案 »

  1.   

    UpdateProject 和 AddProject 方法中是否重新绑定数据??
    如果是,将绑定数据的语句去掉
      

  2.   

    你修改了DataTable或者DataSet里的数据了,重新取数据库即可
      

  3.   

    if you are changing the collection, don't use foreach, use normal for loopfor (int i=this.grdPredetermine.Items.Count-1; i>=0; i--)
    {}
      

  4.   

    在执行foreach循环的时候,你不能改变正在迭代的对象,在你这里就是指this.grdPredetermine.Items。在迭代过程中你改变了这个对象,就必然引发这样的错误。如果你必须在循环中修改,就用普通for循环。