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 _Default : System.Web.UI.Page
{
    protected void Page_Init(object sender, EventArgs e)
    {
        RadGrid1.ItemCommand += new GridCommandEventHandler(RadGrid1_ItemCommand);
    }
    string filterExpression;
    bool setFilterExpression = false;
    protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
    {
        if (e.CommandName == RadGrid.FilterCommandName && ((Pair)e.CommandArgument).Second.ToString() == "HireDate" && ((Pair)e.CommandArgument).First.ToString()=="EqualTo")
        {
            GridFilteringItem item = e.Item as GridFilteringItem;
            var date = ((RadDatePicker)item["HireDate"].Controls[0]).SelectedDate;
            filterExpression = "(Convert.ToDateTime(iif(it[\"HireDate\"]==Convert.DBNull,null,it[\"HireDate\"])) >= DateTime.Parse(\"" + date.ToString() + "\")) AND (Convert.ToDateTime(iif(it[\"HireDate\"]==Convert.DBNull,null,it[\"HireDate\"])) < DateTime.Parse(\"" + date.Value.AddHours(12).ToString() + "\"))";
            setFilterExpression = true;

        }
    }

    protected override void OnPreRender(EventArgs e)
    {
        if (setFilterExpression)
        {
            setFilterExpression = false;
            RadGrid1.MasterTableView.FilterExpression = filterExpression;
            RadGrid1.Rebind();
        }

        base.OnPreRender(e);
    }

}
