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

Aggregate group footer with GridHyperLinkColumn or GridTemplateColumn

9 Answers 322 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Phil
Top achievements
Rank 1
Phil asked on 17 Oct 2008, 06:47 PM
I have a RadGrid that I need to put hyperlinks on the dollar value in a column of the RadGrid that will link to more details and I also need that column to aggregate the sum of each of those dollar amount and put it in the group footer for each group.  Neither the GridHyperLinkColumn or GridTemplateColumn have the Aggregate property like the GridBoundColumn. 

How would I be able to aggregate the values of a GridHyperLinkColumn or GridTemplateColumn so there's a total in the group footer?

9 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 20 Oct 2008, 06:40 AM
Hi Phil,

You can use regular bound column to achieve this:
<%@ Page Language="C#" %> 
 
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 
<script runat="server"
 
    protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e) 
    { 
        System.Data.DataTable table = new System.Data.DataTable(); 
        table.Columns.Add(new System.Data.DataColumn("ID", typeof(int))); 
        table.Columns.Add(new System.Data.DataColumn("UnitsInStock", typeof(int))); 
        table.Columns.Add(new System.Data.DataColumn("UnitPrice", typeof(decimal))); 
 
        Random Random1 = new Random(); 
        for (int i = 0; i < 10; i++) 
        { 
            table.Rows.Add(new object[] { i, i < 5? 10 : 20, Random1.NextDouble() * 100 }); 
        } 
 
        RadGrid1.DataSource = table
    } 
</script> 
 
<html xmlns="http://www.w3.org/1999/xhtml"
<head runat="server"
    <title></title
</head> 
<body> 
    <form id="form1" runat="server"
        <div> 
            <asp:ScriptManager ID="ScriptManager1" runat="server" /> 
            <telerik:RadGrid ID="RadGrid1" AutoGenerateColumns="false" runat="server" 
                OnNeedDataSource="RadGrid1_NeedDataSource"
                <MasterTableView ShowGroupFooter="true"
                    <Columns> 
                        <telerik:GridBoundColumn DataField="ID" HeaderText="ID" /> 
                        <telerik:GridBoundColumn DataField="UnitsInStock" HeaderText="UnitsInStock" /> 
                        <telerik:GridBoundColumn Aggregate="sum" DataField="UnitPrice" HeaderText="UnitPrice" 
                            DataFormatString="<a href='Details.aspx?ID={0}'>More details for {0:c}</a>" FooterAggregateFormatString="Total : {0:c}" /> 
                    </Columns> 
                    <GroupByExpressions> 
                        <telerik:GridGroupByExpression> 
                            <GroupByFields> 
                                <telerik:GridGroupByField FieldName="UnitsInStock" /> 
                            </GroupByFields> 
                            <SelectFields> 
                                <telerik:GridGroupByField FieldName="UnitsInStock" /> 
                            </SelectFields> 
                        </telerik:GridGroupByExpression> 
                    </GroupByExpressions> 
                </MasterTableView> 
            </telerik:RadGrid> 
        </div> 
    </form> 
</body> 
</html> 
 


Kind regards,
Vlad
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Phil
Top achievements
Rank 1
answered on 20 Oct 2008, 03:06 PM
Thanks. 

Also, is there any way to have multiple data fields selected like I can with the DataNavigateUrlFields property of the GridHyperLinkColumn?  I need a way to put multiple query string values in the Url.
0
Bodevain Svensson
Top achievements
Rank 1
answered on 23 Oct 2008, 08:47 AM
Phil, as far as I know the bound column does not support multiple fields and hence can not be used as DataNavigateUrlFields/DataNavigateFormatString properties of a hyperlink column. Consider using the second column type if needed.

Bodevain
0
Senthil
Top achievements
Rank 1
answered on 17 Apr 2014, 05:42 PM
Thanks for the update, i am using exactly the below code,

<telerik:GridBoundColumn Aggregate="sum" DataField="Test" HeaderText="Test" HeaderStyle-HorizontalAlign="Right" ItemStyle-HorizontalAlign="Right"
DataFormatString="<a href='/Test/Test.aspx'> {0:c}</a>" FooterAggregateFormatString="{0:c}">
<FooterStyle Font-Bold="true" HorizontalAlign="Right"></FooterStyle>
</telerik:GridBoundColumn>

The above code is working fine but if export data to excel, its giving an error "File error. Some number formats may have been lost " and i am getting the value in excel like
<a href='/Test/Test.aspx'> $78.32</a>

May i know how can we achive this? I need grid with Hyberlik, Aggregate and export to excel and PDF.

Thanks in Advance!!!
Aggregate
0
Shinu
Top achievements
Rank 2
answered on 21 Apr 2014, 10:39 AM
Hi Senthil,

I was unable to replicate such an issue at my end. Please take a look at the sample code snippet. Provide your full code snippet if this doesn't help.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" DataSourceID="SqlDataSource1"    ShowFooter="true" AllowPaging="true">
    <ExportSettings ExportOnlyData="true">
    </ExportSettings>
    <MasterTableView DataKeyNames="OrderID" CommandItemDisplay="Top">
        <CommandItemSettings ShowExportToExcelButton="true" ShowExportToPdfButton="true" />
        <Columns>
            <telerik:GridBoundColumn UniqueName="OrderID" DataField="OrderID" HeaderText="OrderID">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="ShipCity" HeaderText="ShipCity" UniqueName="ShipCity">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn Aggregate="sum" DataField="ShipVia" HeaderText="ShipVia" DataFormatString="<a href='~/0Default.aspx'> {0:c}</a>" FooterAggregateFormatString="{0:c}">
            </telerik:GridBoundColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
    SelectCommand="SELECT  * FROM [Orders]"></asp:SqlDataSource>

Thanks,
Shinu
0
Senthil
Top achievements
Rank 1
answered on 21 Apr 2014, 09:08 PM
Thanks Shinu.

Actually the code is working fine however if we add below code <format="Biff">, i  am getting the file error, while export to excel. and i am getting the hyperlink(url) with data.
<ExportSettings ExportOnlyData="true">
<Excel Format="Biff" />
</ExportSettings>

How can we resolve this? Thanks in Advance!

0
Shinu
Top achievements
Rank 2
answered on 22 Apr 2014, 04:04 AM
Hi Senthil,

Please try setting the SuppressColumnDataFormatStrings="true" for the export.

ASPX:
<ExportSettings ExportOnlyData="true" SuppressColumnDataFormatStrings="true">
    <Excel Format="Biff" />
</ExportSettings>

Thanks,
Shinu
0
Senthil
Top achievements
Rank 1
answered on 22 Apr 2014, 12:58 PM
Thanks for the update.

The solution is working fine. i am able to get data alone in the excel.

But before load the excel i am getting error like " File error. Some number formats may have been lost".

How can we resolve this? Thanks in advance.
0
Maria Ilieva
Telerik team
answered on 25 Apr 2014, 11:28 AM
Hi,

This is generic Excel error and you could try to fix it using the steps below:

In that workbook, Press Ctrl+1, Number tab, In Category, select Custom. In the Type field on the right, start selecting all the custom formats one by one. If you see the "Delete" option enabled, you would need to Delete that format incase you no longer use it. Do this for all the formats and then try opening the file again.
Also, give a look to this webpage:
http://support.microsoft.com/kb/171279

Regards,
Maria Ilieva
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.

 
Tags
Grid
Asked by
Phil
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Phil
Top achievements
Rank 1
Bodevain Svensson
Top achievements
Rank 1
Senthil
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Maria Ilieva
Telerik team
Share this question
or