using System;
using System.Data;
using System.Configuration;
using System.Collections;
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 Filtering : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {
    }

    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridFilteringItem)
        {
            GridFilteringItem filteringItem = e.Item as GridFilteringItem;

            Button filter = new Button();
            filter.Text = "Filter by contains";
            filter.CommandName = "CustomFilter";
            filter.CommandArgument = "Filter";

            Button noFilter = new Button();
            noFilter.Text = "No Filter";
            noFilter.CommandName = "CustomFilter";
            noFilter.CommandArgument = "NoFilter";

            filteringItem["ShipName"].Controls.Add(filter);
            filteringItem["ShipName"].Controls.Add(noFilter);

            //hide filter button for ShipName column
            filteringItem["ShipName"].Controls[1].Visible = false;


            //set dimensions for the filter textboxes
            RadNumericTextBox orderIdBox = filteringItem["OrderID"].Controls[0] as RadNumericTextBox;
            orderIdBox.Width = Unit.Pixel(50);
            RadMaskedTextBox postalCodeBox = filteringItem["ShipPostalCode"].Controls[0] as RadMaskedTextBox;
            postalCodeBox.Width = Unit.Pixel(50);
            RadDateInput orderDateBox = filteringItem["OrderDate"].Controls[1] as RadDateInput;
            orderDateBox.Width = Unit.Pixel(50);
            RadNumericTextBox freightBox = filteringItem["Freight"].Controls[0] as RadNumericTextBox;
            freightBox.Width = Unit.Pixel(50);
            RadDatePicker shippedDateBox = filteringItem["ShippedDate"].Controls[0] as RadDatePicker;
            shippedDateBox.Width = Unit.Pixel(150);
        }


    }

    
    protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
    {
        
            
        if (e.CommandName == "CustomFilter")
        {
                        if (e.CommandArgument.ToString() == "Filter")
            {
                string command = e.CommandArgument.ToString();
                GridFilteringItem filter = (GridFilteringItem)e.Item;
                filter.FireCommandEvent("Filter", new Pair("Contains", "ShipName"));
            }
            else if (e.CommandArgument.ToString() == "NoFilter")
            {
                GridFilteringItem filter = (GridFilteringItem)e.Item;
                filter.FireCommandEvent("Filter", new Pair("NoFilter", "ShipName"));
            }

        }
        
    }
}
