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

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack || Session["data"] == null)
        {
            Session["data"] = new BusinessObjectCollection(20);
        }

        RadGrid1.NeedDataSource += new Telerik.Web.UI.GridNeedDataSourceEventHandler(RadGrid1_NeedDataSource);
    }

    protected void Picker1_SelectedDateChanged(object sender, Telerik.Web.UI.Calendar.SelectedDateChangedEventArgs e)
    {
        Session["selectedDate"] = e.NewDate;

        RadGrid1.Rebind();
    }

    void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
    {
        if (Session["selectedDate"] == null)
        {
            RadGrid1.DataSource = Session["data"];
        }
        else
        {
            DateTime selectedDate = (DateTime)Session["selectedDate"];
            BusinessObjectCollection data = Session["data"] as BusinessObjectCollection;
            BusinessObjectCollection result = new BusinessObjectCollection();
            result.Clear();


            foreach (BusinessObject obj in data)
            {
                if (obj.Date == selectedDate)
                {
                    result.Add(obj);
                }
            }

            RadGrid1.DataSource = result;
        }
    }
}