Collection was modified; Enumeration operation may not execute. Exception handling
When you run the program, you encounter such an exception, and after careful examination, you find that you are using foreach ... The in syntax is caused by the remove or add to collection, just change the Foreach method to the For method.
for (int i = 0; i < This.prtdeallist.Items.Count; i++) {RepeaterItem RepeaterItem = this . prtdeallist. Items[i]; if (Repeateritem.itemtype = = ListItemType.Item | | repeateritem.itemtype = = listitemtype.alternatingitem) { HtmlInputCheckBox cbdealisselected = Repeateritem.findcontrol ("Ckppguid") as HtmlInputCheckBox; HiddenField Hfdealguid = Repeateritem.findcontrol ("HiddenField2") as HiddenField; if (cbdealisselected.checked) {Dtdealitemwrapper Deali TEM = Dtdealitemwrapper.findbyid (Hfdealguid.value); Dtdealwrapper dtdeal = null; if (Dealitem = = null) {dtdeal = Dtdealwrapper.findbyid (hfdealguid.value ); } if (Dealitem! = null) {dealitem.ddicrmreportstatus = false; Dtdealitemwrapper.update (Dealitem); String Linecode = "Linecode:" + dealitem.ddilinecode; Recorddeletelog (Hfdealguid.value, Linecode); } else if (dtdeal! = null) {DTDEAL.DDCRMREPORTST ATUs = false; Dtdealwrapper.update (Dtdeal); String Linecode = "Dd_no:" + dtdeal.ddno; Recorddeletelog (Hfdealguid.value, Linecode); } } } }
Collection was modified; Enumeration operation may not execute. Exception handling