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;

public partial class RadGridFooterInfoContextMenu : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void RadGrid1_GroupsChanging(object sender, GridGroupsChangingEventArgs e)
    {
        if (e.Action == GridGroupsChangingAction.Group)
        {
            GridColumn col = GetColumnByGroupExpression(e.Expression);
            ChangeColumnsAggregate(col, true);
        }
        else if (e.Action == GridGroupsChangingAction.Ungroup)
        {
            GridColumn col = GetColumnByGroupExpression(e.Expression);
            ChangeColumnsAggregate(col, false);
        }
    }
    private GridColumn GetColumnByGroupExpression(GridGroupByExpression gridGroupByExpression)
    {
        foreach (GridColumn col in RadGrid1.MasterTableView.RenderColumns)
        {
            if (col.GetDefaultGroupByExpression() == gridGroupByExpression.Expression)
            {
                return col;
            }
        }
        return null;
    }
    private void ChangeColumnsAggregate(GridColumn column, bool condition)
    {
        switch (column.UniqueName)
        {
            case "OrderID": (column as GridBoundColumn).Aggregate = condition ?
                GridAggregateFunction.Count : GridAggregateFunction.None; break;
            case "Freight": (column as GridNumericColumn).Aggregate = condition ?
                GridAggregateFunction.Sum : GridAggregateFunction.None; break;
            case "ShipCountry": (column as GridBoundColumn).Aggregate = condition ?
                GridAggregateFunction.Min : GridAggregateFunction.None; break;
            default: break;
        }
    }
}