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

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
    {
        OleDbConnection MyOleDbConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" +
      Server.MapPath("~/App_Data/Nwind.mdb"));
        OleDbDataAdapter MyOleDbDataAdapter = new OleDbDataAdapter();
        MyOleDbDataAdapter.SelectCommand = new OleDbCommand("SELECT TOP 10 CustomerID,CompanyName, ContactName FROM Customers", MyOleDbConnection);
        DataTable myDataTable;
        if (Session["DataSource"] != null)
        {
            myDataTable = (DataTable)Session["DataSource"];
        }
        else
        {
            myDataTable = new DataTable();
            MyOleDbConnection.Open();
            try
            {
                MyOleDbDataAdapter.Fill(myDataTable);
            }
            finally
            {
                MyOleDbConnection.Close();
            }
            myDataTable.PrimaryKey = new DataColumn[] { myDataTable.Columns["CustomerID"] };
            Session["DataSource"] = myDataTable;
        }
        RadGrid1.DataSource = myDataTable;
    }
    protected void RadGrid1_DeleteCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
    {
        string ID = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["CustomerID"].ToString();
        DataTable table = (DataTable)Session["DataSource"];
        if (table.Rows.Find(ID) != null)
        {
            table.Rows.Find(ID).Delete();
            table.AcceptChanges();
            Session["DataSource"] = table;
        }
    } 
}
