An item with the same key has already been added.

6 posts, 0 answers
  1. Larry
    Larry avatar
    33 posts
    Member since:
    Apr 2009

    Posted 30 Jun 2010 Link to this post

    I have a RadGrid in a FormView.  I bind to the FormView with an object datasource. The grid binds to a List that is a property of the object datasource object.   The first time loading the page (in Edit Mode) which retrieves a record everything works fine and the grid binds to the List.    When I hit Submit to save everything I get the error.  We are running 2010.1.415.35
                        <telerik:RadGrid   
                            ID="RegGrid"   
                            runat="server" 
                            Skin="Windows7"   
                            BorderStyle="None" 
                            GridLines="None"   
                            Width="650px"   
                            PageSize="20"   
                            AllowFilteringByColumn="true" 
                            AllowSorting="True"   
                            ShowFooter="True"   
                            AllowPaging="True"   
                            AutoGenerateColumns="False" 
                            EnableLinqExpressions="false"   
                            AllowAutomaticInserts="false"   
                            AllowAutomaticUpdates="false" 
                            AllowAutomaticDeletes="false"    
                            OnItemCreated="RegGrid_ItemCreated" 
                            OnItemCommand="RegGrid_ItemCommand" 
                            OnItemDataBound="RegGrid_ItemDataBound" 
                            OnDeleteCommand="RegGrid_DeleteCommand" 
                            OnInsertCommand="RegGrid_InsertCommand" 
                            OnUpdateCommand="RegGrid_UpdateCommand" 
                            OnNeedDataSource="RegGrid_NeedDataSource">  
                            <ClientSettings> 
                                <Selecting AllowRowSelect="false" /> 
                            </ClientSettings> 
                            <MasterTableView   
                                DataKeyNames="regRequest,item" 
                                EditMode="InPlace" 
                                AllowFilteringByColumn="True" 
                                ShowFooter="True"   
                                CommandItemDisplay="Top"   
                                InsertItemPageIndexAction="ShowItemOnCurrentPage" 
                                CommandItemSettings-AddNewRecordText="Add Package"   
                                ItemStyle-VerticalAlign="top" 
                                AlternatingItemStyle-VerticalAlign="top"   
                                HeaderStyle-HorizontalAlign="Center">  
                                <Columns> 
                                    <telerik:GridTemplateColumn AllowFiltering="false">  
                                        <ItemTemplate> 
                                            <asp:LinkButton ID="LinkButton2" runat="server" CommandName="Edit">Edit</asp:LinkButton> 
                                            <asp:LinkButton ID="LinkButton1" runat="server" CommandName="Delete" OnClientClick="javascript:return confirm('Delete this Reg Item?')">Delete</asp:LinkButton> 
                                        </ItemTemplate> 
                                        <EditItemTemplate> 
                                            <asp:LinkButton ID="LinkButton3" runat="server" Text='<%# ((GridItem)Container).OwnerTableView.IsItemInserted? "Insert" : "Update" %>' 
                                                CommandName='<%# ((GridItem)Container).OwnerTableView.IsItemInserted? "PerformInsert" : "Update" %>'></asp:LinkButton> 
                                            <asp:LinkButton ID="LinkButton4" runat="server" CommandName="Cancel">Cancel</asp:LinkButton> 
                                        </EditItemTemplate> 
                                    </telerik:GridTemplateColumn> 
                                    <telerik:GridBoundColumn DataField="regRequest" Visible="false" /> 
                                    <telerik:GridDropDownColumn UniqueName="ddcRegItems" DataField="item" ListTextField="name" ListValueField="item"   
                                         DataSourceID="sqlRegRequestItem" HeaderText="Reg Item" DropDownControlType="DropDownList" EmptyListItemText="- Select A Package -" EmptyListItemValue="0" /> 
                                    <telerik:GridBoundColumn DataField="quantity" HeaderText="Qty" DataFormatString="{0:n}" /> 
                                    <telerik:GridBoundColumn DataField="price" HeaderText="Price" DataFormatString="{0:C}" ReadOnly="true" /> 
                                    <telerik:GridCalculatedColumn HeaderText="Total (USD)" UniqueName="ExtendedPrice"   
                                        DataType="System.Double" DataFields="quantity, price" Expression="{0}*{1}" FooterText="Total : " 
                                        Aggregate="Sum" DataFormatString="{0:C}" /> 
                                </Columns> 
                            </MasterTableView> 
                            <PagerStyle Mode="NextPrevAndNumeric" /> 
                        </telerik:RadGrid> 
        protected void RegGrid_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)  
        {  
              
            RIM.Event.Resources.Regcode.Request _request = (RIM.Event.Resources.Regcode.Request)(Session["Request"]);  
            if (_request != null)  
            {  
                // SELECT NON-DELETED ITEMS  
                List<RegItem> _regitems = _request.regItems.FindAll(p => p.deleted != true);  
                  
                ((RadGrid)source).DataSource = _regitems;  
            }  
        } 
  2. Larry
    Larry avatar
    33 posts
    Member since:
    Apr 2009

    Posted 30 Jun 2010 Link to this post

    I forgot to list the Stack Trace;

    [ArgumentException: An item with the same key has already been added.]
       System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) +51
       System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) +7464444
       System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value) +11
       Telerik.Web.UI.GridDataTableFromEnumerable.FillData() +5080
       Telerik.Web.UI.GridResolveEnumerable.Initialize() +55
       Telerik.Web.UI.GridResolveEnumerable.EnsureInitialized() +40
       Telerik.Web.UI.GridResolveEnumerable.get_DataTable() +31
       Telerik.Web.UI.GridEnumerableFromDataView..ctor(GridTableView owner, IEnumerable enumerable, Boolean CaseSensitive, Boolean autoGenerateColumns, GridColumnCollection presentColumns, String[] additionalField, Boolean retrieveAllFields) +221
       Telerik.Web.UI.GridDataSourceHelper.CreateGridEnumerable(GridTableView owner, IEnumerable enumerable, Boolean caseSensitive, Boolean autoGenerateColumns, GridColumnCollection presentColumns, String[] additionalField, Boolean retrieveAllFields) +155
       Telerik.Web.UI.GridDataSourceHelper.GetResolvedDataSource(GridTableView owner, Object dataSource, String dataMember, Boolean caseSensitive, Boolean autoGenerateColumns, GridColumnCollection presentColumns, String[] additionalField, Boolean retrieveAllFields) +556
       Telerik.Web.UI.GridTableView.get_ResolvedDataSource() +219
       Telerik.Web.UI.GridTableView.CreateChildControls(IEnumerable dataSource, Boolean useDataSource) +73
       System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +57
       System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +114
       System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +31
       System.Web.UI.WebControls.DataBoundControl.PerformSelect() +142
       Telerik.Web.UI.GridTableView.PerformSelect() +38
       System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73
       Telerik.Web.UI.GridTableView.DataBind() +353
       Telerik.Web.UI.RadGrid.DataBind() +165
       System.Web.UI.Control.DataBindChildren() +211
       System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102
       System.Web.UI.Control.DataBind() +15
       System.Web.UI.Control.DataBindChildren() +211
       System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102
       System.Web.UI.Control.DataBind() +15
       System.Web.UI.Control.DataBindChildren() +211
       System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102
       System.Web.UI.Control.DataBind() +15
       System.Web.UI.Control.DataBindChildren() +211
       System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102
       System.Web.UI.Control.DataBind() +15
       System.Web.UI.Control.DataBindChildren() +211
       System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102
       System.Web.UI.Control.DataBind() +15
       System.Web.UI.Control.DataBindChildren() +211
       System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102
       System.Web.UI.WebControls.FormView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) +1461
       System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +57
       System.Web.UI.WebControls.FormView.PerformDataBinding(IEnumerable data) +12
       System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +114
       System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +31
       System.Web.UI.WebControls.DataBoundControl.PerformSelect() +142
       System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73
       System.Web.UI.WebControls.FormView.DataBind() +4
       System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82
       System.Web.UI.WebControls.FormView.EnsureDataBound() +166
       System.Web.UI.WebControls.BaseDataBoundControl.OnPreRender(EventArgs e) +22
       System.Web.UI.Control.PreRenderRecursiveInternal() +80
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Larry
    Larry avatar
    33 posts
    Member since:
    Apr 2009

    Posted 01 Jul 2010 Link to this post

    setting EnableLinqExpressions to true fixed this problem.
  5. Miguel
    Miguel avatar
    25 posts
    Member since:
    Dec 2010

    Posted 11 Jan 2011 Link to this post

    Hi Larry,

    I have the same problem and if I set EnableLinqExpressions  to true I get a new error:
    Unable to cast object of type 'DynamicClass1' to type 'OES.Entity.OES_GeneracionGas'
    and 'OES.Entity.OES_GeneracionGas' is a custom object.

    Do you know what this is happening?

    Thanks!
    Miguel
  6. Miguel
    Miguel avatar
    25 posts
    Member since:
    Dec 2010

    Posted 13 Jan 2011 Link to this post

    Hi, can anyone help me please?

    Thanks!
    Miguel
  7. Meera
    Meera avatar
    12 posts
    Member since:
    Aug 2012

    Posted 14 Jun 2012 Link to this post

    set
    RegGrid.DataSource=null ;
    before rebinding.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017