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


public partial class _Default : System.Web.UI.Page
{
    public DataTable GetDataTable(string query)
    {
        String ConnString = ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;
        SqlConnection conn = new SqlConnection(ConnString);
        SqlDataAdapter adapter = new SqlDataAdapter();
        adapter.SelectCommand = new SqlCommand(query, conn);

        DataTable myDataTable = new DataTable();

        conn.Open();
        try
        {
            adapter.Fill(myDataTable);
        }
        finally
        {
            conn.Close();
        }

        return myDataTable;
    }

    protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
    {
        RadGrid1.DataSource = GetDataTable("SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address, PostalCode FROM Customers");
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        GridGroupByExpression expression = new GridGroupByExpression();
        GridGroupByField gridGroupByField = new GridGroupByField();

        gridGroupByField = new GridGroupByField();
        gridGroupByField.FieldName = "ContactTitle";
        gridGroupByField.HeaderText = "ContactTitle";
        gridGroupByField.HeaderValueSeparator = ": ";
        gridGroupByField.FormatString = "{0}";
        expression.SelectFields.Add(gridGroupByField);

        gridGroupByField.SortOrder = GridSortOrder.None;
        expression.GroupByFields.Add(gridGroupByField);

        RadGrid1.MasterTableView.GroupByExpressions.Add(expression);
    }
}



 

