Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,
I am working on Telerik.
I want to add Footer at bottom of Gridview so it can show the totals for that column's property.

I m work on Windows form.
Code is below.

GridViewSummaryItem summaryItem = new GridViewSummaryItem();
summaryItem.Name = "Units";
summaryItem.Aggregate = GridAggregateFunction.Count;

GridViewSummaryRowItem summaryRowItem = new GridViewSummaryRowItem();
summaryRowItem.Add(summaryItem);

this.GridViewWorkInProgress.SummaryRowsBottom.Add(summaryRowItem);


thats code i added but it will not include footer at bottom.


it will shows error of Null reference Exception unhandled.
Posted
Updated 5-Feb-15 23:48pm
v3
Comments
Thanks7872 6-Feb-15 3:44am    
Ok. Add it. Come back when you face any issues doing so.
dlpanchal 6-Feb-15 5:00am    
i cant add it.
not getting how it could done.
Thanks7872 6-Feb-15 5:09am    
i cant add it

Why?
dlpanchal 6-Feb-15 5:11am    
i dont know how to add footer
Thanks7872 6-Feb-15 5:18am    
Then use Google. Search engines were designed to overcome such issues. If everyone else knows it,why don't you? Don't expect some one to code for you.

XML
Telerik RadGrid provides a method to define aggregates on a per column basis from design time and render the results inside the respective column's footer. Aggregate calculations are supported for GridBoundColumns and GridCalculatedColumns.

Steps:-

--Subscribe to the your DataBound event of Grid
--Iterate through the rows in the underlying grid source
--Sum up the total and insert it in the respective column footer

aspx-

<telerik:RadGrid ID="RG1" runat="server">
  <MasterTableView AutoGenerateColumns="False" ShowFooter="True" AllowPaging="true">
    <FooterStyle BackColor="#cc6633"></FooterStyle>
    <Columns>
      <telerik:GridBoundColumn HeaderText="Item Count" DataField="Item Count" UniqueName="Item Count" />
    </Columns>
  </MasterTableView>
  <PagerStyle Mode="NextPrevAndNumeric" />
</telerik:RadGrid>

in C#-

private void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem dataItem = (GridDataItem)e.Item;
        int fieldValue = int.Parse(dataItem["Item Count"].Text);
        total = total + fieldValue;
    }
    if (e.Item is GridFooterItem)
    {
        GridFooterItem footerItem = (GridFooterItem)e.Item;
        footerItem["Item Count"].Text = "Total: " + total.ToString();
    }
}

protected void RadGrid1_DataBound(object sender, System.EventArgs e)
{
    DataTable gridTable = GetDataTable("SELECT * FROM [Order Details]");

    foreach (DataRow row in gridTable.Rows)
    {
        grandTotal = grandTotal + int.Parse(row["Quantity"]);
    }
    GridFooterItem footerItem = RadGrid1.MasterTableView.GetItems(GridItemType.Footer)[0];
    footerItem["Item Count"].Text = footerItem["Item Count"].Text + "<br> Total for all pages: " + grandTotal.ToString();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900