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.Data;

public partial class _Default : System.Web.UI.Page
{
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

        RadGrid1.NeedDataSource += new GridNeedDataSourceEventHandler(RadGrid1_NeedDataSource);
        RadGrid1.PreRender += new EventHandler(RadGrid1_PreRender);
    }

    void RadGrid1_PreRender(object sender, EventArgs e)
    {
        for (int i = 0; i < RadGrid1.MasterTableView.GroupByExpressions.Count; i++)
        {
            if (RadGrid1.MasterTableView.GroupByExpressions[i].GroupByFields[0].FieldName == "ID")
            {
                RadGrid1.MasterTableView.GroupByExpressions.RemoveAt(i);
            }
        }

        GridGroupByField field = new GridGroupByField();
        field.FieldName = "ID";
        field.HeaderText = "ID";
        GridGroupByExpression ex = new GridGroupByExpression();
        ex.GroupByFields.Add(field);
        ex.SelectFields.Add(field);
        RadGrid1.MasterTableView.GroupByExpressions.Add(ex);

        RadGrid1.Rebind();
    }

    void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        DataTable table = new DataTable();
        table.Columns.Add("ID");
        table.Columns.Add("Item");
        table.Columns.Add("Date", typeof(DateTime));
        for (int i = 1; i < 8; i++)
        {
            table.Rows.Add(i, "Item" + i.ToString(), DateTime.Now.AddDays(i));
        }
        RadGrid1.DataSource = table;
    }
}
