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

public partial class RadGridProgrammaticFrozenColumns : System.Web.UI.Page
{
    protected void Page_Init(object sender, System.EventArgs e)
    {
        RadGrid grid = new RadGrid();
        grid.ID = "RadGrid1";
        grid.AllowPaging = true;
        grid.NeedDataSource += grid_NeedDataSource;

        grid.Width = Unit.Pixel(800);
        grid.MasterTableView.Width = Unit.Pixel(1200);

        grid.ClientSettings.Scrolling.AllowScroll = true;
        grid.ClientSettings.Scrolling.UseStaticHeaders = true;
        grid.ClientSettings.Scrolling.FrozenColumnsCount = 2;
        grid.ClientSettings.Scrolling.ScrollHeight = Unit.Empty;

        Form.Controls.Add(grid);
    }
    protected void grid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        String ConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
        SqlConnection conn = new SqlConnection(ConnString);
        SqlDataAdapter adapter = new SqlDataAdapter();
        adapter.SelectCommand = new SqlCommand("SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address FROM Customers", conn);

        DataTable myDataTable = new DataTable();

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

        (sender as RadGrid).DataSource = myDataTable;
    }
}