using System;
using System.Collections.Generic;
using System.Linq;
using Telerik.Web.UI;

public partial class Default : System.Web.UI.Page 
{
    private const string dummyDataKey = "DUMMY_DATA_KEY";

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            GenerateDummyTestData();
            grid1.DataSource = Session[dummyDataKey] as List<Person>;
            grid1.DataBind();
        }
    }

    private void GenerateDummyTestData()
    {
        //Generate dummy data for testing
        var dummyTestData = new List<Person>();
        for (int i = 0; i < 50; i++)
        {
            dummyTestData.Add(new Person(){ ID = i, Name = String.Format("Johny{0}", i)});
        }

        Session[dummyDataKey] = dummyTestData;
    }

    protected void grid1_DeleteCommand(object source, GridCommandEventArgs e)
    {
        if(e.CommandName == "Delete")
        {
            //Perform delete logic
            //(For simple demo, remove item from list)

            var dataItem = e.Item as GridDataItem;
            var key = Convert.ToInt32(dataItem["ID"].Text);
            var dummyTestData = Session[dummyDataKey] as List<Person>;

            var item = (from p in dummyTestData
                        where p.ID == key
                        select p).First();

            dummyTestData.Remove(item);

            Session[dummyDataKey] = dummyTestData;

            //No need to manually call DataBind - will occur implicitly
        }
    }

    protected void grid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
    {
        grid1.DataSource = Session[dummyDataKey] as List<Person>;
    }
}

public class Person
{
    public int ID { get; set; }
    public string Name { get; set; }
}
