using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Telerik.Web.UI;
using System.Collections.Generic;
using System.Collections;
using System.Data.OleDb;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, System.EventArgs e)
    {
        RadGrid NewGrid = new RadGrid();
        NewGrid.ID = "RadGrid1";
        NewGrid.NeedDataSource += new GridNeedDataSourceEventHandler(RadGrid1_NeedDataSource);
        PlaceHolder1.Controls.Add(NewGrid);  //Add RadGrid to the Controls collection of the placeholder
        if (!IsPostBack)
        {
            NewGrid.Skin = "Web20";
            NewGrid.AutoGenerateColumns = false;
            NewGrid.AllowFilteringByColumn = true;
            NewGrid.AllowSorting = true;
            NewGrid.AllowPaging = true;

            GridBoundColumn boundColumn;
            boundColumn = new GridBoundColumn();
            NewGrid.MasterTableView.Columns.Add(boundColumn);
            boundColumn.DataField = "CustomerID";
            boundColumn.HeaderText = "CustomerID";
            boundColumn = new GridBoundColumn();
            NewGrid.MasterTableView.Columns.Add(boundColumn);
            boundColumn.DataField = "ContactName";
            boundColumn.HeaderText = "Contact Name";
        }
    }

    void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Server.MapPath("~/App_Data/Nwind.mdb"));
        OleDbDataAdapter adapter = new OleDbDataAdapter();
        adapter.SelectCommand = new OleDbCommand("SELECT * FROM Customers", conn);
        DataTable myDataTable = new DataTable();
        conn.Open();
        try
        {
            adapter.Fill(myDataTable);
        }
        finally
        {
            conn.Close();
        }
        (sender as RadGrid).DataSource = myDataTable;
    }
}