How to display sum of template column in group footer

2 posts, 0 answers
  1. Amol
    Amol avatar
    57 posts
    Member since:
    Apr 2008

    Posted 07 May 2009 Link to this post

    Hi,

    In Rad grid I want to use Group Footer that calculate average percentage of every column in a group , In my project I need to use GridTemplate column on a grid so can you tell me that how do I apply Group Footer in rad grid using GridTemplate column?

    Thanks,
    Amol
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 07 May 2009 Link to this post

    Hello Amol,

    Try out the following code snippet for showing group footer for template column.

    ASPX
     
    <telerik:radgrid id="RadGrid1" runat="server" allowpaging="True" ShowFooter="true" ShowGroupPanel="true" datasourceid="SqlDataSource1" Skin="Office2007" OnPreRender="RadGrid1_PreRender">  
    <MasterTableView DataSourceID="SqlDataSource1" AutoGenerateColumns="False" ShowGroupFooter="True">  
    <Columns> 
       . . .  
    <telerik:GridTemplateColumn UniqueName="TempCol" > 
      <ItemTemplate> 
        <asp:Label ID="Label1" Text='<%# Eval("Number") %>' runat="server">  
        </asp:Label> 
      </ItemTemplate> 
    </telerik:GridTemplateColumn> 
       . . .  
    </Columns> 
    </MasterTableView> 
    <ClientSettings AllowDragToGroup="True">  
    </ClientSettings> 
    </telerik:radgrid> 

    CS
    protected void RadGrid1_PreRender(object sender, EventArgs e)  
    {  
        int num, avg = 0, total = 0;  
        int length = RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader).Length;  
        for (int i = 0; i < length; i++)  
        {  
            GridGroupHeaderItem groupHeader = (GridGroupHeaderItem)RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader)[i];  
            GridItem[] children = groupHeader.GetChildItems();  
            num = 0; total = 0;  
            foreach (GridItem child in children)  
            {  
                GridDataItem dataItem = child as GridDataItem;  
                total = total + Convert.ToInt32((child.FindControl("Label1"as Label).Text);  
                num++;  
                GridTableView tableView = (GridTableView)dataItem.NamingContainer;  
            }  
            avg = total / num;  
            GridGroupFooterItem groupfooter = (GridGroupFooterItem)RadGrid1.MasterTableView.GetItems(GridItemType.GroupFooter)[i];  
            groupfooter.Cells[(RadGrid1.MasterTableView.GetColumn("TempCol").OrderIndex) + 1].Text = avg.ToString();  
        }  

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top