Hello.
I have grid with custom aggregate in one column and export to PDF/Excel abilities. When I view in browser aggregation works ok, but there is no aggregation in exported documents. Here is my code:
And code-behind:
What I am doing wrong?
I have grid with custom aggregate in one column and export to PDF/Excel abilities. When I view in browser aggregation works ok, but there is no aggregation in exported documents. Here is my code:
<telerik:RadGrid ID="RadGrid1" runat="server" GridLines="None" AllowPaging="True" OnItemCreated="RadGrid1ItemCreated" OnNeedDataSource="RadGrid1NeedDataSource" OnCustomAggregate="RadGrid1CustomAggregate" OnExcelMLExportRowCreated="RadGrid1ExcelMlExportRowCreated" OnExcelMLExportStylesCreated="RadGrid1ExcelMlExportStylesCreated" AllowFilteringByColumn="True" AllowSorting="True" CellSpacing="0" OnItemDataBound="RadGrid1ItemDataBound"> <ExportSettings ExportOnlyData="true" IgnorePaging="true" OpenInNewWindow="true"> <Excel Format="ExcelML" /> <Pdf PageTitle="Charity Print-Out" Title="Charity Print-Out" PageHeight="210mm" PageWidth="500mm" DefaultFontFamily="Arial Unicode MS" PageBottomMargin="20mm" PageTopMargin="20mm" PageLeftMargin="20mm" PageRightMargin="20mm" /> </ExportSettings> <PagerStyle Mode="NextPrevAndNumeric" /> <MasterTableView AutoGenerateColumns="False" DataKeyNames="DonationId" CommandItemDisplay="Top" Width="100%" AllowPaging="True" NoDetailRecordsText="" NoMasterRecordsText="" ShowGroupFooter="true" UseAllDataFields="True"> <CommandItemSettings ShowExportToExcelButton="true" ShowAddNewRecordButton="False" ShowRefreshButton="False" ShowExportToPdfButton="True" /> <PagerStyle Mode="NextPrevAndNumeric" /> <Columns> <telerik:GridBoundColumn DataField="CHR_CHARITY_NAME" HeaderText="Charity Name" ReadOnly="True" UniqueName="CHR_CHARITY_NAME" Visible="False" /> <telerik:GridBoundColumn DataField="DonationInternalId" HeaderText="Client Donation ID" ReadOnly="True" UniqueName="DonationInternalId" /> <telerik:GridBoundColumn DataField="DonorName" HeaderText="Donor's Name" ReadOnly="True" UniqueName="DonorName" /> <telerik:GridBoundColumn DataField="DonorAddress" HeaderText="Donor's Address" ReadOnly="True" UniqueName="DonorAddress" /> <telerik:GridBoundColumn DataField="EmailAddress" HeaderText="Email" ReadOnly="True" UniqueName="EmailAddress" /> <telerik:GridBoundColumn DataField="PermissionToContact" HeaderText="Permission To Contact" ReadOnly="True" UniqueName="PermissionToContact" /> <telerik:GridBoundColumn DataField="DateOfDonation" HeaderText="Donation Date" ReadOnly="True" UniqueName="DateOfDonation" /> <telerik:GridBoundColumn DataField="NotesToCharity" HeaderText="Donor Notes" ReadOnly="True" UniqueName="NotesToCharity" /> <telerik:GridBoundColumn DataField="DonationAmount" HeaderText="Donation Amount" ReadOnly="True" UniqueName="DonationAmount" DataFormatString="{0:C}" Aggregate="Custom" FooterText=" " /> </Columns> <GroupByExpressions> <telerik:GridGroupByExpression> <GroupByFields> <telerik:GridGroupByField FieldName="CHR_CHARITY_NAME" /> </GroupByFields> <SelectFields> <telerik:GridGroupByField FieldName="CHR_CHARITY_NAME" HeaderText=" " HeaderValueSeparator=" " /> <telerik:GridGroupByField FieldName="CHR_BN_NUMBER" HeaderText="-" HeaderValueSeparator=" " /> </SelectFields> </telerik:GridGroupByExpression> </GroupByExpressions> </MasterTableView></telerik:RadGrid>And code-behind:
protected void RadGrid1CustomAggregate(object sender, GridCustomAggregateEventArgs e){ if (e.Item.DataItem == null) { return; } const string result = "<table style=\"border-collapse:collapse;text-align:left;\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">" + "<tr><td style=\"text-align:left;\">Total Donations:</td><td>${0}</td></tr>" + "<tr><td style=\"text-align:left;\">Processing & Transaction Fees @ 8%:</td><td>${1}</td></tr>" + "<tr><td style=\"text-align:left;\">Net Donation Amount:</td><td>${2}</td></tr>" + "</table>"; double totalDonations = 0, netDonationAmount = 0, fees = 0; foreach (DataRow row in dataTable.Rows) { if (row["CHR_CHARITY_NAME"].ToString() != ((DataRowView)e.Item.DataItem).Row.ItemArray[0].ToString()) { continue; } if (row["DonationAmount"] != null) { totalDonations += (double)row["DonationAmount"]; } if (row["NetDonationAmount"] != null) { netDonationAmount += (double)row["NetDonationAmount"]; } if (row["Fees"] != null) { fees += (double)row["Fees"]; } } e.Result = String.Format(result, totalDonations.ToString("0.00"), fees.ToString("0.00"), netDonationAmount.ToString("0.00"));}What I am doing wrong?