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

Exception in Aggregate with Calculated Column

4 Answers 136 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jose
Top achievements
Rank 2
Jose asked on 24 Nov 2010, 12:44 PM
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

4 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 24 Nov 2010, 01:36 PM
Hello Jose,

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

Thanks,
Princy.
0
Jose
Top achievements
Rank 2
answered on 24 Nov 2010, 06:33 PM
Hi Princy,

Thank you very much.
Now it's works fine.
Regards
Jose
0
Daniel Aquere
Top achievements
Rank 2
answered on 03 Jul 2011, 01:34 PM
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
0
Mira
Telerik team
answered on 06 Jul 2011, 03:40 PM
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!

Tags
Grid
Asked by
Jose
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Jose
Top achievements
Rank 2
Daniel Aquere
Top achievements
Rank 2
Mira
Telerik team
Share this question
or