using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using System.Web.UI.HtmlControls;
using System.Data;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    private void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {

    }

    protected void RadGrid1_PreRender(object sender, EventArgs e)
    {
        int length = RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader).Length;
        for (int i = 0; i < length; i++)
        {
            double total = 0;

            GridGroupHeaderItem groupHeader = (GridGroupHeaderItem)RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader)[i];
            GridItem[] children = groupHeader.GetChildItems();
            foreach (GridItem child in children)
            {
                if (child is GridDataItem)
                {
                    GridDataItem childItem = child as GridDataItem;
                    total += double.Parse((childItem["Freight"].FindControl("Label1") as Label).Text);
                }
            }
            GridGroupFooterItem groupFooter = (GridGroupFooterItem)RadGrid1.MasterTableView.GetItems(GridItemType.GroupFooter)[i];

            HtmlTable tbl = new HtmlTable();
            HtmlTableCell cell1 = new HtmlTableCell();
            HtmlTableRow row = new HtmlTableRow();
            row.Align = "right";
            cell1.Width = "100";
            cell1.BorderColor = "red";
            cell1.InnerText = total.ToString();
            row.Cells.Add(cell1);
            tbl.Rows.Add(row);

            groupFooter["Freight"].Controls.Clear();
            groupFooter["Freight"].Controls.Add(tbl);

        }
    }
}
