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 _Default : System.Web.UI.Page
{
    private void Page_Load(object sender, System.EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            RadGrid1.EditIndexes.Add(0);
        }
    }

    private DataTable DataSource1
    {
        get
        {
            if (Session[Request.CurrentExecutionFilePath + "Dates1"] == null)
            {
                DataTable table = new DataTable("Events");
                DataColumn column = new DataColumn();
                column.ColumnName = "Dates";
                column.DataType = typeof(System.DateTime);
                table.Columns.Add(column);

                table.Rows.Add(new object[] { new DateTime(2006, 3, 10) });
                table.Rows.Add(new object[] { new DateTime(2006, 3, 15) });
                table.Rows.Add(new object[] { null });
                table.Rows.Add(new object[] { System.DBNull.Value });
                table.Rows.Add(new object[] { new DateTime(2006, 4, 1) });

                Session[Request.CurrentExecutionFilePath + "Dates1"] = table;
            }

            return (DataTable)Session[Request.CurrentExecutionFilePath + "Dates1"];
        }
    }

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

    protected void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e)
    {
        RadDatePicker picker = (RadDatePicker)e.Item.FindControl("picker1");
        object newDate = picker.DbSelectedDate;

        DataSource1.Rows[e.Item.DataSetIndex]["Dates"] = newDate == null ? DBNull.Value : newDate;
    }

    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridEditableItem && e.Item.IsInEditMode)
        {
            GridEditableItem editItem = (GridEditableItem)e.Item;
            RadDatePicker picker = (RadDatePicker)editItem.FindControl("picker1");
            picker.SharedCalendar = sharedCalendar;
        }
    }



    private DataTable DataSource2
    {
        get
        {
            if (Session[Request.CurrentExecutionFilePath + "Dates2"] == null)
            {
                DataTable table = new DataTable("Events");
                DataColumn column = new DataColumn();
                column.ColumnName = "Dates";
                column.DataType = typeof(System.DateTime);
                table.Columns.Add(column);

                table.Rows.Add(new object[] { new DateTime(2006, 3, 10) });
                table.Rows.Add(new object[] { new DateTime(2006, 3, 15) });
                table.Rows.Add(new object[] { null });
                table.Rows.Add(new object[] { System.DBNull.Value });
                table.Rows.Add(new object[] { new DateTime(2006, 4, 1) });

                Session[Request.CurrentExecutionFilePath + "Dates2"] = table;
            }

            return (DataTable)Session[Request.CurrentExecutionFilePath + "Dates2"];
        }

    }
}