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;

public partial class Default4 : System.Web.UI.Page
{
    protected void RadGrid2_ItemCommand(object source, GridCommandEventArgs e)
    {        
        if (e.CommandName == RadGrid.FilterCommandName)
        {
            Pair filterPair = (Pair)e.CommandArgument;

            switch (filterPair.Second.ToString())
            {
                case "OrderDate":
                    GridHeaderItem headerItem = e.Item.OwnerTableView.GetItems(GridItemType.Header)[0] as GridHeaderItem;
                    this.startDate = (headerItem[filterPair.Second.ToString()].FindControl("FromOrderDatePicker") as RadDatePicker).SelectedDate;
                    this.endDate = (headerItem[filterPair.Second.ToString()].FindControl("ToOrderDatePicker") as RadDatePicker).SelectedDate;
                    break;                
                default:
                    break;
            }
        }
    }
    protected void btnShowAll_Click(object sender, System.Web.UI.ImageClickEventArgs e)
    {
        RadGrid2.MasterTableView.FilterExpression = string.Empty;

        foreach (GridColumn column in RadGrid2.MasterTableView.RenderColumns)
        {
            if (column is GridBoundColumn)
            {
                GridBoundColumn boundColumn = column as GridBoundColumn;
                boundColumn.CurrentFilterValue = string.Empty;
            }
        }
        this.startDate = null;
        this.endDate = null;
        
        RadGrid2.MasterTableView.Rebind();

    }
    protected void RadGrid1_PreRender(object sender, EventArgs e)
    {
        RadGrid2.MasterTableView.GetItems(GridItemType.FilteringItem)[0].Expanded = false;
    }
    protected DateTime? startDate
    {
        set
        {
            ViewState["strD"] = value;
        }
        get
        {
            if (ViewState["strD"] != null)
                return (DateTime)ViewState["strD"];
            else
                return new DateTime(1996, 7, 4);
        }
    }
    protected DateTime? endDate
    {
        set
        {
            ViewState["endD"] = value;
        }
        get
        {
            if (ViewState["endD"] != null)
                return (DateTime)ViewState["endD"];
            else
                return new DateTime(1998, 5, 6);
        }
    }
}