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

public partial class Selecting : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //foreach  (GridDataItem item in RadGrid1.MasterTableView.Items)
        //{
        //    if (item.Selected == true)
        //        Session["h"] = item.KeyValues;
        //}
        RadGrid1.NeedDataSource += new GridNeedDataSourceEventHandler(RadGrid1_NeedDataSource);
    }

    protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
    {
        RadGrid1.DataSource = SampleData;
    }

    public DataTable SampleData
    {
        get
        {
            if (Session["_data"] == null || !Page.IsPostBack)
            {
                System.Data.DataTable table = new System.Data.DataTable();
                table.Columns.Add("ID", Type.GetType("System.Int32"));
                table.Columns.Add("Name", Type.GetType("System.String"));
                table.Columns.Add("Date", Type.GetType("System.DateTime"));
                table.Columns.Add("Value", Type.GetType("System.Double"));
                table.Columns.Add("Order", Type.GetType("System.Int32"));

                Random rand = new Random();

                for (int i = 0; i < 100; i++)
                {
                    table.Rows.Add(i,
                                   "Item " + i.ToString(),
                                   DateTime.Today.AddDays(-10).AddDays(rand.NextDouble() * 20),
                                   rand.NextDouble() * 1000,
                                   i);
                }

                Session["_data"] = table;
            }

            DataTable original = (DataTable)Session["_data"];
            DataTable ret = original.Clone();
            DataRow[] sortedRows = original.Select("", "Order ASC");
            foreach (DataRow row in sortedRows)
            {
                ret.Rows.Add(row.ItemArray);
            }

            return ret;
        }
    }
}
