RadGrid - An item with the same key has already been added

6 posts, 0 answers
  1. Guillermo
    Guillermo avatar
    1 posts
    Member since:
    Nov 2014

    Posted 12 Nov 2014 Link to this post

    I have a RadGrid with GridCalculatedColumn when rebind...

    An item with the same key has already been added.

    I'm running 2013.3.1015.45.

    ASPX

    <telerik:RadGrid ID="grillaAfectos" runat="server" AllowPaging="True" AllowSorting="True"
    GridLines="None" AutoGenerateColumns="true" PageSize="10"  EnableLinqExpressions="false"
    Skin="Metro" Visible="true" Width="98%" OnNeedDataSource="grillaAfectos_NeedDataSource" OnItemDataBound="grillaAfectos_ItemDataBound">
    <MasterTableView AutoGenerateColumns="False" AllowCustomPaging="true" NoMasterRecordsText="No se encontraron registros para mostrar.">
    <Columns>
    <telerik:GridBoundColumn HeaderText="Cuenta Contable" DataField="Detalle.NumeroCuenta"  HeaderStyle-Width="20%">
    </telerik:GridBoundColumn>                                                                                   
    <telerik:GridCalculatedColumn HeaderText="Descripcion" DataType="System.String" DataFields="Proveedor.ProveedorID, Detalle.CodigoDocumentoPago.Codigo, Detalle.NumeroDocumento, Detalle.FechaMovimiento.Date" Expression='{0} + " " + {1} + "/" + {2} + " " + {3}'>
    </telerik:GridCalculatedColumn>
    <telerik:GridBoundColumn HeaderText="Monto" DataField="Total" DataFormatString="{0:C0}" ItemStyle-HorizontalAlign="Right" >
    </telerik:GridBoundColumn>
    <telerik:GridBoundColumn HeaderText="Nuevo Monto" DataField="MontoNuevo" DataFormatString="{0:C0}" ItemStyle-HorizontalAlign="Right" >
    </telerik:GridBoundColumn>
    <telerik:GridTemplateColumn HeaderStyle-Width="20px" FilterControlAltText="Filter TemplateColumn column" HeaderText="Acción" UniqueName="TemplateColumn" ItemStyle-HorizontalAlign="Center" >
    <%--<ItemTemplate>
    <asp:HyperLink ID="lnkEditar" runat="server" ImageUrl="~/Content/Img/Grid/edit.png" BorderWidth="0px" BorderStyle="None" ToolTip="Editar" NavigateUrl=<%#"Javascript:onBtnActionsClick('ActualizarTasas.aspx?id=" + Eval("DocumentosPagadosID").ToString() + "&dolar=" + ViewState("dolar") + "','Tasas','Tasas',800,200)"%> Visible="false"/>
    </ItemTemplate>--%>
    </telerik:GridTemplateColumn>
    <telerik:GridBoundColumn HeaderText="" DataField="FacturaDetalleID" Visible="false" >
    </telerik:GridBoundColumn>
    </Columns>
    </MasterTableView>
    <ClientSettings AllowColumnsReorder="True" AllowDragToGroup="True" ReorderColumnsOnClient="True">
    </ClientSettings>
    </telerik:RadGrid>

    Code Behind
    Dim grillaAfectos As RadGrid = DirectCast(RadPanelBar5.FindItemByValue("Desembolsos").FindControl("grillaAfectos"), RadGrid)
    grillaAfectos.DataSource = objNotaDebito.Tasas
              grillaAfectos.DataBind()
    Protected Sub grillaAfectos_NeedDataSource(sender As Object, e As GridNeedDataSourceEventArgs)
                objNotaDebito = DirectCast(objCache("NotaDebito"), NotaDebitoVO)
                Dim grillaAfectos As RadGrid = DirectCast(RadPanelBar5.FindItemByValue("Desembolsos").FindControl("grillaAfectos"), RadGrid)
                Dim startIndex As Int32 = grillaAfectos.CurrentPageIndex
                Dim maximumRows As Int32 = grillaAfectos.PageSize
                If objNotaDebito.Tasas IsNot Nothing AndAlso objNotaDebito.Tasas.Count > 0 Then
                    objNotaDebito.Tasas = objNotaDebito.Tasas.Skip((startIndex) * maximumRows).Take(maximumRows).ToList()
                End If
     
                grillaAfectos.DataSource = objNotaDebito.Tasas
            End Sub


    If I remove this column works perfectly....
  2. Pavlina
    Admin
    Pavlina avatar
    6187 posts

    Posted 17 Nov 2014 Link to this post

    Hello,

    Could you download the latest internal build of Telerik UI controls and make sure that the same problem still persists?

    Regards,
    Pavlina
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. ravi
    ravi avatar
    1 posts
    Member since:
    Feb 2015

    Posted 04 Feb 2015 Link to this post

    Hi,
    I am developing an application using Rad Controls.In this there is a rad grid which contains checkbox,on selection of it based on the id i am loading relevant data to the another radGrid next to it in the same page.
    For the first time selection data is getting loaded properly,But on the next checkbox selection i am getting the error an item with the same key has already been added.
     
    Sharing the code
     Collapse | Copy Code<telerik:RadGrid ID="radGrid1" AutoGenerateColumns="false" AllowPaging="true" runat="server"
    ShowHeader="true" AllowAutomaticUpdates="true" AllowAutomaticInserts="true" AllowAutomaticDeletes="true"
    Width="43%" Style="float: left;" Visible="true" >
    <MasterTableView DataKeyNames="USERNAME,USERID">
    <Columns>
    <telerik:GridTemplateColumn>
    <ItemTemplate>
    <asp:CheckBox ID="UserSelect" runat="server" HeaderText="Select" AutoPostBack="true"
    OnCheckedChanged="UserSelect_CheckedChanged" />
    </ItemTemplate>
    </telerik:GridTemplateColumn>
    <telerik:GridBoundColumn UniqueName="USERID" DataField="USERID" HeaderText="User Id"
    Visible="false">
    </telerik:GridBoundColumn>
    <telerik:GridBoundColumn UniqueName="USERNAME" DataField="USERNAME" HeaderText="User Name">
    </telerik:GridBoundColumn>
    </Columns>
    </MasterTableView>
    </telerik:RadGrid>
    Checkbox change event
     Collapse | Copy Code protected void UserSelect_CheckedChanged(object sender, EventArgs e)
    {
    CheckBox chk = (CheckBox)sender;
    GridDataItem itm = (GridDataItem)chk.NamingContainer;
    RadRoles.DataSource = new string[] { };
    RadRoles.DataBind();
     
    foreach (GridDataItem row in radGrid1.MasterTableView.Items)
    {
    CheckBox chk1 = (CheckBox)row.FindControl("UserSelect");
     
    if (chk1.Checked == true)
    {
    DataTable dt = null;
    //dt will fetch the values from the DB
    RadRoles.DataSource = dt.DefaultView;
    RadRoles.DataBind();
    }
    }
    }
  4. Pavlina
    Admin
    Pavlina avatar
    6187 posts

    Posted 06 Feb 2015 Link to this post

    Hello,

    Did you encounter the same problem if you populate the grid through NeedDataSource instead of using simple data binding calling DataBind()?

    Regards,
    Pavlina
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  5. Nency
    Nency avatar
    1 posts
    Member since:
    Jul 2015

    Posted 18 Aug 2015 in reply to Pavlina Link to this post

    Hi, Were you able to resolve this issue? I am facing the same error when trying to apply filter on PrerRender.

     protected void GridViewNotifications_PreRender(object sender, EventArgs e)
            {
                GridViewNotifications.MasterTableView.FilterExpression = "([TransactionNo]=SR5350-201501001)";
                GridColumn column = GridViewNotifications.MasterTableView.GetColumnSafe("TransactionNo");
                column.CurrentFilterFunction = GridKnownFunction.EqualTo;
                column.CurrentFilterValue = "SR5350-201501001";
               GridViewNotifications.Rebind();
                
            } 

  6. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 21 Aug 2015 Link to this post

    Hello Nency,

    Can you please make sure that you are binding the RadGrid through the NeedDataSource event? Sharing your page markup as well as the related code behind will help us further investigate the issue and provide proper solution for your case.

    Regards,
    Maria Ilieva
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top