Exception in Aggregate with Calculated Column

5 posts, 1 answers
  1. Jose
    Jose avatar
    38 posts
    Member since:
    Apr 2009

    Posted 24 Nov 2010 Link to this post

    Hello,

    I'm having problems to add Aggregate to a GridCalculatedColumn.

    This is my code (due to space I'm only copying a part of it):

    <telerik:GridTableView runat="server" AllowSorting="true" DataKeyNames="QuotationLineId"
        Caption="Quotation Lines" Name="QuotationLines" PageSize="10"
        CommandItemDisplay="Top" AllowPaging="true" AutoGenerateColumns="False"
        GridLines="None" AllowFilteringByColumn="false" ShowFooter="True">
     
        <Columns>
            <telerik:GridButtonColumn ButtonType="ImageButton" Reorderable="False"
                Resizable="False" ShowFilterIcon="False" ShowSortIcon="False"
                UniqueName="EditButton" ImageUrl="~/Images/Edit.png" CommandName="Edit">
                <ItemStyle Width="20px" HorizontalAlign="Center" VerticalAlign="Middle" />
            </telerik:GridButtonColumn>
            <telerik:GridBoundColumn DataField="QuotationLineId" HeaderText="Id"
                UniqueName="QuotationLineId" Visible="false">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn HeaderText="Units" DataField="Units" UniqueName="Units" ItemStyle-Width="25px"
                ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right" DataFormatString="{0:0.00}">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn HeaderText="Description" DataField="Description" UniqueName="Description">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn HeaderText="Cost" DataField="Cost" UniqueName="Cost" ItemStyle-HorizontalAlign="Right"
                HeaderStyle-HorizontalAlign="Right" DataFormatString="{0:c}" ItemStyle-Width="65px">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn HeaderText="Price" DataField="Price" UniqueName="Price" ItemStyle-HorizontalAlign="Right"
                HeaderStyle-HorizontalAlign="Right" DataFormatString="{0:c}" ItemStyle-Width="65px">
            </telerik:GridBoundColumn>
            <telerik:GridCalculatedColumn UniqueName="TotalCost" HeaderText="Total Cost"
                DataFields="Units, Cost" Expression='{0}*{1}' ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right"
                DataFormatString="{0:c}" ItemStyle-Width="65px" Aggregate="Sum" FooterStyle-HorizontalAlign="Right"
                FooterAggregateFormatString="{0:c}">
            </telerik:GridCalculatedColumn>
            <telerik:GridCalculatedColumn UniqueName="TotalPrice" HeaderText="Total Price"
                DataFields="Units, Price" Expression='{0}*{1}' ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right"
                DataFormatString="{0:c}" ItemStyle-Width="65px">
            </telerik:GridCalculatedColumn>
            <telerik:GridCalculatedColumn UniqueName="Margin" HeaderText="Margin"
                DataFields="Cost, Price" Expression='1-({0}/{1})' ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right"
                DataFormatString="{0:0.00%}" ItemStyle-Width="25px">
            </telerik:GridCalculatedColumn>
            <telerik:GridButtonColumn ButtonType="ImageButton" Reorderable="False"
                Resizable="False" ShowFilterIcon="False" ShowSortIcon="False"
                UniqueName="DeleteButton" ImageUrl="~/Images/Delete.png" CommandName="Delete"
                ConfirmDialogType="RadWindow" ConfirmText="Are you sure you want to delete this record?" ConfirmTitle="Delete record..."
                ConfirmDialogHeight="130px">
                <ItemStyle Width="20px" HorizontalAlign="Center" VerticalAlign="Middle" />
            </telerik:GridButtonColumn>
        </Columns>
     
    </telerik:GridTableView>


    The error is:

    Microsoft JScript runtime error:
    Sys.WebForms.PageRequestManagerServerErrorException: Exception has been thrown by the target of an invocation.

    If I write the same code in a bind column all works fine.

    Regards
    Jose
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 24 Nov 2010 Link to this post

    Hello Jose,

    Try to set DataType for GridCalculated column as "System.Int32" and check whether that make any differences.

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jose
    Jose avatar
    38 posts
    Member since:
    Apr 2009

    Posted 24 Nov 2010 Link to this post

    Hi Princy,

    Thank you very much.
    Now it's works fine.
    Regards
    Jose
  5. Daniel Aquere
    Daniel Aquere avatar
    85 posts
    Member since:
    Mar 2011

    Posted 03 Jul 2011 Link to this post

    Hi Guys,

    I have the same error, but, occurs when I show a custom column (number of records in filter):

    <telerik:GridTemplateColumn HeaderStyle-HorizontalAlign="Center" AllowFiltering="false" DataType="System.Int32"
                                                    HeaderText="id" ItemStyle-HorizontalAlign="Center" UniqueName="id" Groupable="false"
                                                    Aggregate="Count" FooterStyle-HorizontalAlign="Center" FooterStyle-Font-Bold="true"
                                                    FooterText=" ">
                                                    <ItemTemplate>
                                                        <asp:Label ID="idnum" runat="server" Font-Size="Smaller" />
                                                    </ItemTemplate>
                                                    <HeaderStyle HorizontalAlign="Center" />
                                                    <ItemStyle HorizontalAlign="Center" />
                                                </telerik:GridTemplateColumn>

     protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                Label lbl = e.Item.FindControl("idnum") as Label;
                lbl.Text = (e.Item.ItemIndex + RadGrid2.MasterTableView.PagingManager.FirstIndexInPage + 1).ToString();
            }
        }

    Please, what can be?

    Thanks, best

    Daniel
  6. Mira
    Admin
    Mira avatar
    1124 posts

    Posted 06 Jul 2011 Link to this post

    Hello Daniel,

    Please try removing the DataType property of the template column and let me know whether it helps.

    I am looking forward to your reply.

    Greetings,
    Mira
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

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