This is a migrated thread and some comments may be shown as answers.

Batch Edit Mode - Collection was modified; enumeration operation may not execute.

2 Answers 229 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 2
Chris asked on 10 Jul 2013, 03:58 PM
Hi,
 I am using the Q2 2013 release (2013.2.611.45) version of your controls. On the page I have two databound combos and a grid. The datasource for the grid uses control parameters linked to the two dropdowns. If the grid is in any other EditMode other than Batch, everything works as expected. Both dropdowns have code in the databound event to either select a specific item or add a 'Choose' item.

The grid is empty on initial page load and then once a Form is chosens from the dropdown it then populates with a list of pupils.

If I put the grid into Batch EditMode then when I select a form from the dropdown I get the following error: 

Collection was modified; enumeration operation may not execute.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Collection was modified; enumeration operation may not execute.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[InvalidOperationException: Collection was modified; enumeration operation may not execute.]
   System.Web.UI.ControlCollectionEnumerator.MoveNext() +12538578
   Telerik.Web.UI.RadFormDecorator.FindAndDecorateControls(Control parent) +779
   Telerik.Web.UI.RadFormDecorator.FindAndDecorateControls(Control parent) +755
   Telerik.Web.UI.RadFormDecorator.FindAndDecorateControls(Control parent) +755
   Telerik.Web.UI.RadFormDecorator.FindAndDecorateControls(Control parent) +755
   Telerik.Web.UI.RadFormDecorator.FindAndDecorateControls(Control parent) +755
   Telerik.Web.UI.RadFormDecorator.FindAndDecorateControls(Control parent) +755
   Telerik.Web.UI.RadFormDecorator.FindAndDecorateControls(Control parent) +755
   Telerik.Web.UI.RadFormDecorator.ControlPreRender() +761
   System.Web.UI.Control.PreRenderRecursiveInternal() +113
   System.Web.UI.Control.PreRenderRecursiveInternal() +222
   System.Web.UI.Control.PreRenderRecursiveInternal() +222
   System.Web.UI.Control.PreRenderRecursiveInternal() +222
   System.Web.UI.Control.PreRenderRecursiveInternal() +222
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4297


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18044              


I have tried deleting the grid and rebuilding using the configuration tools, same result. Here is my grid and code behind, also I am using a custom skin set at application level in the web.config and a formdecorator.

<%@ Page Title="Stars Pluses Minuses" Language="C#" MasterPageFile="~/Staff/Staff.master" AutoEventWireup="true"
         CodeFile="StarsPlusMinus.aspx.cs" Inherits="Staff.Reporting.AR.StarsPlusMinus" %>
 
<asp:Content ID="Content1" ContentPlaceHolderID="head_staff" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="main_staff" Runat="Server">
    <asp:Panel ID="SelectionPanel" runat="server" CssClass="SelectionPanel">
        <telerik:RadComboBox ID="FormComboBox" runat="server" Label="Form: " Width="150px" CssClass="PupilChooserCombo"
                             AutoPostBack="True" OnDataBound="FormComboBox_OnDataBound" DataSourceID="FormDataSource" DataTextField="DESCRIPTION" DataValueField="CODE">
        </telerik:RadComboBox>
        <telerik:RadComboBox ID="PeriodComboBox" runat="server" Label="Period: " Width="150px"
                             CssClass="PupilChooserCombo" AutoPostBack="True" DataSourceID="PeriodDataSource"
                             DataTextField="PERIOD_NAME" DataValueField="PERIOD_ID" OnDataBound="PeriodComboBox_DataBound">
        </telerik:RadComboBox>
    </asp:Panel>
    <telerik:RadGrid ID="PupilGrid" runat="server" AllowAutomaticUpdates="True" AutoGenerateColumns="False"
        CellSpacing="0" DataSourceID="GridDataSource" GridLines="None">
        <ExportSettings>
            <Pdf>
                <PageHeader>
                    <LeftCell Text=""></LeftCell>
 
                    <MiddleCell Text=""></MiddleCell>
 
                    <RightCell Text=""></RightCell>
                </PageHeader>
 
                <PageFooter>
                    <LeftCell Text=""></LeftCell>
 
                    <MiddleCell Text=""></MiddleCell>
 
                    <RightCell Text=""></RightCell>
                </PageFooter>
            </Pdf>
        </ExportSettings>
 
        <ValidationSettings EnableModelValidation="False" EnableValidation="False" />
 
        <MasterTableView ClientDataKeyNames="LINE_ID" CommandItemDisplay="TopAndBottom" DataKeyNames="LINE_ID" DataSourceID="GridDataSource"
                         EditMode="Batch"  ShowHeadersWhenNoRecords="True">
            <CommandItemSettings ExportToPdfText="Export to PDF" ShowAddNewRecordButton="False" ShowCancelChangesButton="True"
                ShowRefreshButton="False" ShowSaveChangesButton="True"></CommandItemSettings>
 
            <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
                <HeaderStyle Width="20px"></HeaderStyle>
            </RowIndicatorColumn>
 
            <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column" Created="True">
                <HeaderStyle Width="20px"></HeaderStyle>
            </ExpandCollapseColumn>
 
            <Columns>
                <telerik:GridBoundColumn DataField="INFORMAL_NAME" FilterControlAltText="Filter INFORMAL_NAME column" HeaderText="INFORMAL_NAME"
                    ReadOnly="True" SortExpression="INFORMAL_NAME" UniqueName="INFORMAL_NAME">
                    <ColumnValidationSettings>
                        <ModelErrorMessage Text="" />
                    </ColumnValidationSettings>
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn ReadOnly="True" DataField="ACADEMIC_HOUSE_DESCRIPTION" FilterControlAltText="Filter ACADEMIC_HOUSE_DESCRIPTION column"
                    HeaderText="ACADEMIC_HOUSE_DESCRIPTION" SortExpression="ACADEMIC_HOUSE_DESCRIPTION" UniqueName="ACADEMIC_HOUSE_DESCRIPTION">
                    <ColumnValidationSettings>
                        <ModelErrorMessage Text="" />
                    </ColumnValidationSettings>
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn ReadOnly="True"  DataField="FORM_DESC" FilterControlAltText="Filter FORM_DESC column"
                    HeaderText="FORM_DESC" SortExpression="FORM_DESC" UniqueName="FORM_DESC">
                    <ColumnValidationSettings>
                        <ModelErrorMessage Text="" />
                    </ColumnValidationSettings>
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="STARS" DataType="System.Decimal" FilterControlAltText="Filter STARS column"
                    HeaderText="STARS"  SortExpression="STARS" UniqueName="STARS">
                    <ColumnValidationSettings>
                        <ModelErrorMessage Text="" />
                    </ColumnValidationSettings>
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="PLUSES" DataType="System.Decimal" FilterControlAltText="Filter PLUSES column"
                    HeaderText="PLUSES"  SortExpression="PLUSES" UniqueName="PLUSES">
                    <ColumnValidationSettings>
                        <ModelErrorMessage Text="" />
                    </ColumnValidationSettings>
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="MINUSES" DataType="System.Decimal" FilterControlAltText="Filter MINUSES column"
                    HeaderText="MINUSES" ReadOnly="True" SortExpression="MINUSES" UniqueName="MINUSES">
                    <ColumnValidationSettings>
                        <ModelErrorMessage Text="" />
                    </ColumnValidationSettings>
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="LINE_ID" DataType="System.Int32" FilterControlAltText="Filter LINE_ID column"
                    HeaderText="LINE_ID" ReadOnly="True" SortExpression="LINE_ID" UniqueName="LINE_ID">
                    <ColumnValidationSettings>
                        <ModelErrorMessage Text="" />
                    </ColumnValidationSettings>
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="HEADER_ID" DataType="System.Int32" FilterControlAltText="Filter HEADER_ID column"
                    HeaderText="HEADER_ID" SortExpression="HEADER_ID" UniqueName="HEADER_ID">
                    <ColumnValidationSettings>
                        <ModelErrorMessage Text="" />
                    </ColumnValidationSettings>
                </telerik:GridBoundColumn>
            </Columns>
 
            <EditFormSettings>
                <EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
            </EditFormSettings>
 
            <BatchEditingSettings EditType="Cell"></BatchEditingSettings>
 
            <PagerStyle PageSizeControlType="RadComboBox"></PagerStyle>
        </MasterTableView>
 
        <PagerStyle PageSizeControlType="RadComboBox"></PagerStyle>
 
        <FilterMenu EnableImageSprites="False"></FilterMenu>
    </telerik:RadGrid>
    <asp:SqlDataSource ID="FormDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:PassMainConnectionString %>"
        SelectCommand="usps_SA_GetForms" SelectCommandType="StoredProcedure">
        <SelectParameters>
            <asp:ProfileParameter Name="ACADEMIC_YEAR" PropertyName="CurrentAcademicYear" Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="PeriodDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:PassMainConnectionString %>"
                       SelectCommand="usps_SA_GetAssessmentPeriods" SelectCommandType="StoredProcedure">
        <SelectParameters>
            <asp:ProfileParameter Name="ACADEMIC_YEAR" PropertyName="CurrentAcademicYear" Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="GridDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:PassMainConnectionString %>"
                       SelectCommand="usps_SA_GetPupilsForSPMGrid" SelectCommandType="StoredProcedure">
        <SelectParameters>
            <asp:Parameter Name="SCHOOL"  Type="String" DefaultValue="SA"/>
            <asp:ControlParameter ControlID="PeriodComboBox" Name="PERIOD_ID" PropertyName="SelectedValue" Type="Int32" />
            <asp:ControlParameter ControlID="FormComboBox" Name="FORM_CODE" PropertyName="SelectedValue" Type="String" />
            <asp:ProfileParameter  Name="ACADEMIC_YEAR" PropertyName="CurrentAcademicYear" Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>
</asp:Content>

using System;
using System.Linq;
using NLog;
using Telerik.Web.UI;
 
namespace Staff.Reporting.AR
{
    public partial class StarsPlusMinus : System.Web.UI.Page
    {
        private readonly Logger _logger = LogManager.GetCurrentClassLogger();
 
        protected void Page_Error(object sender, EventArgs e)
        {
            Exception ex = Server.GetLastError();
            _logger.Fatal(ex);
            Server.ClearError();
            //store exception to display some details to the user
            Session[Profile.DomainUsername + "LastError"] = ex;
            Response.Redirect("/Staff/StaffError.aspx", true);
        }
 
        protected void Page_Load(object sender, EventArgs e)
        {
        }
 
        protected void PeriodComboBox_DataBound(object sender, EventArgs e)
        {
            if (IsPostBack) return;
            //always select the current period on first visit
            var item = PeriodComboBox.Items.FirstOrDefault(i => i.Text.EndsWith("(*)"));
            if (item != null)
                item.Selected = true;
        }
 
        protected void FormComboBox_OnDataBound(object sender, EventArgs e)
        {
            if (IsPostBack) return;
            FormComboBox.Items.Insert(0, new RadComboBoxItem("Choose ...", "XX") { Selected = true });
        }
    }
}

<telerik:RadFormDecorator ID="RadFormDecorator1" runat="server" ControlsToSkip="None" DecoratedControls="All" Skin="MyCustomSkin" />

Any ideas gratefully received.

Thanks

Chris 

2 Answers, 1 is accepted

Sort by
0
Chris
Top achievements
Rank 2
answered on 10 Jul 2013, 04:26 PM
Have done some testing - initially removed the control parameters and used the DataSource Selecting event - to get this to work I had to add the following code to the page_Load event:

protected void Page_Load(object sender, EventArgs e)
       {
           EnsureChildControls();
           PupilGrid.DataBind();
       }

This fixed the issue.

I then reinstated the control parameters leaving the above code in and this too now works as expected.

Can you please confirm that this is the required way to work with a batch grid driven by databound combos or if this is a bug ?

Thanks

Chris
0
Angel Petrov
Telerik team
answered on 15 Jul 2013, 03:36 PM
Hi Chris,

I was not able to reproduce the exact problem but it seems that there is a bug in the current implementation of the control which causes the unwanted behavior. I have already logged it into our system and you can monitor it's progress from here. Our developers will do their best to resolve the matter as soon as possible. For now you can use the workaround provided in your last post.

Thank you for reporting this issue to us. As a token of gratitude I have update your Telerik points. Please accept our apologies for any inconvenience this may have caused you.

Regards,
Angel Petrov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Chris
Top achievements
Rank 2
Answers by
Chris
Top achievements
Rank 2
Angel Petrov
Telerik team
Share this question
or