using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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

public partial class Default : System.Web.UI.Page 
{
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

        Button1.Click += new EventHandler(Button1_Click);
        Repeater1.ItemCommand += new RepeaterCommandEventHandler(Repeater1_ItemCommand);
    }

    void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "Delete")
        {
            var date = DateTime.Parse(e.CommandArgument.ToString());

            for (int i = 0; i < DT.Rows.Count; i++)
            {
                if (DT.Rows[i]["Date"].ToString() == date.ToString())
                {
                    DT.Rows.Remove(DT.Rows[i]);
                }
            }
        }

        Repeater1.DataBind();
    }

    void Button1_Click(object sender, EventArgs e)
    {
        DT.Rows.Add(RadDatePicker1.SelectedDate, TextBox1.Text);
        Repeater1.DataBind();
    }

    public DataTable DT
    {
        get
        {
            if (ViewState["DT"] == null)
            {
                ViewState["DT"] = new DataTable();
            }

            return ViewState["DT"] as DataTable;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            DT.Columns.Add("Date", typeof(DateTime));    
            DT.Columns.Add("Item");

            for (int i = 1; i < 8; i++)
            {
                DT.Rows.Add(DateTime.Now.AddDays(i), "Item" + i.ToString());
            }
        }

        if (RadCalendar1.SelectedDates.Count> 0)
        {
            DT.Rows.Add(RadCalendar1.SelectedDates[RadCalendar1.SelectedDates.Count - 1].Date, "Item");
        }
        Repeater1.DataSource = DT;
        Repeater1.DataBind();
    }
}
