GridDateTimeColumn causing a weird problem

5 posts, 0 answers
  1. blablabla
    blablabla avatar
    23 posts
    Member since:
    Jul 2011

    Posted 28 Oct 2011 Link to this post

    This issue has me totally lost.

    I have a formview with several radcontrols and a UserControl.

    The user control has a RadGrid and an ObjectDataSource.

    When I call the UpdateItem method on the formview with the following code:

    protected void BtnSave_Click(object sender, EventArgs e)
    {
    if (Page.IsValid)
    {
     this.MyFormView.UpdateItem(true);
    }
    }

    I get the following exception:

    InvalidOperationException: Collection was modified; enumeration operation may not execute

    Here's the stack trace:

       
    at System.Web.UI.ControlCollection.ControlCollectionEnumerator.MoveNext()
      at System.Web.UI.WebControls.DataBoundControlHelper.ExtractValuesFromBindableControls(IOrderedDictionary dictionary, Control container)
      at System.Web.UI.WebControls.DataBoundControlHelper.ExtractValuesFromBindableControls(IOrderedDictionary dictionary, Control container)
      at System.Web.UI.WebControls.DataBoundControlHelper.ExtractValuesFromBindableControls(IOrderedDictionary dictionary, Control container)
      at System.Web.UI.WebControls.DataBoundControlHelper.ExtractValuesFromBindableControls(IOrderedDictionary dictionary, Control container)
      at System.Web.UI.WebControls.DataBoundControlHelper.ExtractValuesFromBindableControls(IOrderedDictionary dictionary, Control container)
      at System.Web.UI.WebControls.DataBoundControlHelper.ExtractValuesFromBindableControls(IOrderedDictionary dictionary, Control container)
      at System.Web.UI.WebControls.DataBoundControlHelper.ExtractValuesFromBindableControls(IOrderedDictionary dictionary, Control container)
      at System.Web.UI.WebControls.DataBoundControlHelper.ExtractValuesFromBindableControls(IOrderedDictionary dictionary, Control container)
      at System.Web.UI.WebControls.DataBoundControlHelper.ExtractValuesFromBindableControls(IOrderedDictionary dictionary, Control container)
      at System.Web.UI.WebControls.DataBoundControlHelper.ExtractValuesFromBindableControls(IOrderedDictionary dictionary, Control container)
      at System.Web.UI.WebControls.DataBoundControlHelper.ExtractValuesFromBindableControls(IOrderedDictionary dictionary, Control container)
      at System.Web.UI.WebControls.DataBoundControlHelper.ExtractValuesFromBindableControls(IOrderedDictionary dictionary, Control container)
      at System.Web.UI.WebControls.DataBoundControlHelper.ExtractValuesFromBindableControls(IOrderedDictionary dictionary, Control container)
      at System.Web.UI.WebControls.DataBoundControlHelper.ExtractValuesFromBindableControls(IOrderedDictionary dictionary, Control container)

    -------------

    The stack trace doesn't say much and didn't help me track the problem, but I ended up figuring out that what was causing the problem is a GridDateTimeColumn defined inside the radgrid (there's only one datetime column) that's inside my user control as such:

    <telerik:GridDateTimeColumn DataField="DeadlineDate" UniqueName="DeadlineDate"
         DataFormatString="{0:dd MMM yyyy}" 
    HeaderText="Deadline" />

    When I remove this column, the call to the formview's UpdateItem method works well. When I put it back, I get the error again. I tried playing w/ the properties, binding to another datetime column, recreating the whole file from scratch, removing everything in the code behind file of the user control, and nothing works. The weird thing is, I have datetime columns in other usercontrols built the same way, and everything works fine there.

    Here's the usercontrol definition:

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="GridViewTest.ascx.cs"
        Inherits="TestSolution.WebUI.UserControls.GridViewTest" %>
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
     
    <telerik:RadGrid ID="TestRadGrid" runat="server" AllowFilteringByColumn="True" AutoGenerateColumns="false"
        AllowPaging="True" AllowSorting="True" CellSpacing="0" DataSourceID="TestDataSource"
        GridLines="None" Skin="Office2007">
        <MasterTableView EditMode="InPlace" DataKeyNames="PeriodID">
            <Columns>
                <telerik:GridBoundColumn DataField="PeriodID" UniqueName="PeriodID"
                    Visible="false" />
                <telerik:GridBoundColumn DataField="SpecificityID" UniqueName="SpecificityID" />
                <telerik:GridDateTimeColumn DataField="DeadlineDate" UniqueName="DeadlineDate" DataFormatString="{0:dd MMM yyyy}"
                    HeaderText="Deadline " />
                <telerik:GridBoundColumn DataField="DeadlineDate" UniqueName="DeadlineDate" HeaderText="Deadline" />
                <telerik:GridNumericColumn DataField="OutstandingAmountBeforeDeadline" UniqueName="OutstandingAmountBeforeDeadline"
                    NumericType="Number" HeaderText="O/S Before Repayment" />
                <telerik:GridNumericColumn DataField="InterestAmount" UniqueName="InterestAmount"
                    NumericType="Number" HeaderText="Interest" />
                <telerik:GridCheckBoxColumn DataField="ToDelete" UniqueName="ToDelete" HeaderText="Delete" />
                <telerik:GridEditCommandColumn ButtonType="PushButton" InsertText="Insert" EditText="Edit"
                    CancelText="Cancel" UniqueName="EditCommandColumn" />
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>
    <asp:ObjectDataSource ID="TestDataSource" runat="server" TypeName="TestSolution.WebUI.ObjectDataSource.TestDataSource"
        SelectMethod="GetTestTableByCriterias">
        <SelectParameters>
            <asp:Parameter Name="TestType" Type="Int32" />
            <asp:Parameter Name="SpecificityID" Type="Int32" />
        </SelectParameters>
    </asp:ObjectDataSource>

    Any ideas? :(
  2. Massimiliano
    Massimiliano avatar
    185 posts
    Member since:
    Oct 2012

    Posted 12 Dec 2013 Link to this post

    It seem I've stumbled upon the same issue as the poster above.
    Some additional infos.
    The gridcolumn I'm trying to bind is:
    <telerik:GridDateTimeColumn UniqueName="EndDate" DataField="EndDate" DataType="System.DateTime" HeaderText="Scadenza" EmptyDataText="Nessuna"
                                HtmlEncode="true" ShowFilterIcon="true" FilterImageToolTip=""
                                FilterControlWidth="76%" DataFormatString="{0:dd/MM/yyyy}" PickerType="DatePicker"
                                FilterDateFormat="dd/MM/yyyy" EnableTimeIndependentFiltering="true">
    </telerik:GridDateTimeColumn>
    The field I'm binding is a nullable date time I get from a simple view:
    SELECT     dbo.EVA_PathsPerUser.EndDate, dbo.EVA_Paths.Title, dbo.EVA_PathsPerUser.UserId, dbo.EVA_Plugins.Title AS PluginTitle,
                          dbo.EVA_PathsPerUser.ApplicationId
    FROM         dbo.EVA_PathsPerUser INNER JOIN
                          dbo.EVA_Paths ON dbo.EVA_PathsPerUser.PathId = dbo.EVA_Paths.PathId INNER JOIN
                          dbo.EVA_Plugins ON dbo.EVA_Paths.PluginId = dbo.EVA_Plugins.PluginId

    Some testing that can help you identify the issue:
    - WIth this column apllied I got exactly the same error as the poster above.
    Stack Trace:
     
    System.Web.HttpUnhandledException (0x80004005): Generata eccezione di tipo 'System.Web.HttpUnhandledException'. ---> System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
       in System.Web.UI.ControlCollection.ControlCollectionEnumerator.MoveNext()
       in Telerik.Web.UI.RadFormDecorator.FindAndDecorateControls(Control parent)
       in Telerik.Web.UI.RadFormDecorator.FindAndDecorateControls(Control parent)
    ....
       in System.Web.UI.Page.ProcessRequest(HttpContext context)
       in ASP.admin_users_users_aspx.ProcessRequest(HttpContext context)
       in System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
       in System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
     
    (through ELMAH)
     
    InvalidOperationException: Collection was modified; enumeration operation may not execute.]
       System.Web.UI.ControlCollectionEnumerator.MoveNext() +12538418
       Telerik.Web.UI.RadFormDecorator.FindAndDecorateControls(Control parent) +779
    .....
     
    (original YSOD)

    - If I remove the column the grid binds without issues
    - If I switch the column tipe to a GridBoundColumn with  DataType="System.String" or DataType="System.String" grid binds correctly
    - If I switch to GridTemplateColumn grid binds correctly
    - I modified the db column to be NOT NULLABLE but the issue remains as described above for GridDateTimeColumn
     
    I could solve with a template column and recreate the filtering item with raddatepicker in the template, yet is annoying to not understand why the datecolumn won't work..

    Any hint?
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Daniel
    Admin
    Daniel avatar
    4946 posts

    Posted 17 Dec 2013 Link to this post

    Hello Massimiliano,

    Could you please provide a simple demo that I can use to reproduce the problem on my end?
    This will help me find the root cause and whether it is caused by our control or not.

    Regards,
    Daniel
    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.
  5. QualiWareUA
    QualiWareUA avatar
    54 posts
    Member since:
    Sep 2008

    Posted 25 Feb 2014 Link to this post

    The same problem here. Any solutions? Except for using GridBoundColumn  instead, which is no acceptable in my case?
  6. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 26 Feb 2014 in reply to QualiWareUA Link to this post

    Hi,

    Can you please provide your code snippet to replicate the issue. Below is a sample code snippet that works fine at my end, please check with your code.

    ASPX:
    <telerik:RadGrid runat="server" ID="RadGrid1" AutoGenerateColumns="False" OnNeedDataSource="RadGrid1_NeedDataSource" AllowFilteringByColumn="true" EnableLinqExpressions="false" AllowPaging="true">
            <MasterTableView >
                <Columns>
                    <telerik:GridBoundColumn DataField="OrderID" UniqueName="OrderID" AutoPostBackOnFilter="true" HeaderText="OrderID" SortExpression="OrderID">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="ShipCity" UniqueName="ShipCity" AutoPostBackOnFilter="true" HeaderText="ShipCity" SortExpression="ShipCity">
                    </telerik:GridBoundColumn>
                    <telerik:GridDateTimeColumn DataField="OrderDate" HeaderText="OrderDate" FilterControlWidth="110px" SortExpression="OrderDate" PickerType="DatePicker" EnableTimeIndependentFiltering="true" DataFormatString="{0:MM/dd/yyyy}">
                    </telerik:GridDateTimeColumn>
                </Columns>
            </MasterTableView>
        </telerik:RadGrid>

    C#:
    protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        String ConnString = ConfigurationManager.ConnectionStrings["Northwind_newConnectionString3"].ConnectionString;
        SqlConnection conn = new SqlConnection(ConnString);
        SqlDataAdapter adapter = new SqlDataAdapter();
        adapter.SelectCommand = new SqlCommand("SELECT OrderID, ShipCity,OrderDate FROM Orders", conn);
        DataTable myDataTable = new DataTable();
        conn.Open();
        try
        {
            adapter.Fill(myDataTable);
        }
        finally
        {
            conn.Close();
        }
        RadGrid1.DataSource = myDataTable;
    }

    Thanks,
    Shinu

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017