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

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

    }
    protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
    {
        RadGrid1.DataSource = Data;
    }
    private DataTable Data
    {
        get
        {
            if (Session["Data"] == null)
            {
                DataTable table = new DataTable();
                table.Columns.Add("ID");
                table.Columns.Add("Item");
                table.Columns.Add("Nums", typeof(Int16));
                for (int i = 0; i < 10; i++)
                {
                    table.Rows.Add(i, "Item" + i.ToString(), i * 3);
                }
                Session["Data"] = table;
            }
            return (DataTable)Session["Data"];
        }
        set
        {
            Session["Data"] = value;
        }
    }
    protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
    {
        if (e.CommandName == RadGrid.UpdateCommandName)
        {
            GridEditableItem editedItem = e.Item as GridEditableItem;
            DataTable table = Data;
            DataRow row = table.Select("ID=" + editedItem.GetDataKeyValue("ID"))[0];
            row["Nums"] = (editedItem["Nums"].Controls[0] as TextBox).Text;
            Data = table;
        }
    }
    protected void RadGrid1_ColumnCreated(object sender, GridColumnCreatedEventArgs e)
    {
        if (e.Column.DataType == typeof(Int16) && !(e.Column.UniqueName == "ID"))
        {
            GridBoundColumn column = (e.Column as GridBoundColumn);
            column.Aggregate = GridAggregateFunction.Sum;
            column.FooterAggregateFormatString = "Total: {0}";
        }
    }
}
