using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using Telerik.Web.UI;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    public DataTable GetDataTable(string query)
    {
        String ConnString = ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;
        SqlConnection conn = new SqlConnection(ConnString);
        SqlDataAdapter adapter = new SqlDataAdapter();
        adapter.SelectCommand = new SqlCommand(query, conn);

        DataTable myDataTable = new DataTable();

        conn.Open();
        try
        {
            adapter.Fill(myDataTable);
        }
        finally
        {
            conn.Close();
        }

        return myDataTable;
    }

    protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
    {
        RadGrid1.DataSource = GetDataTable("SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address, PostalCode FROM Customers");
    }

    protected void Unnamed2_Click(object sender, EventArgs e)
    {

        RadFilterContainsFilterExpression expAddress1 = new RadFilterContainsFilterExpression("CompanyName");
        RadFilterContainsFilterExpression expAddress2 = new RadFilterContainsFilterExpression("ContactName");
        RadFilterContainsFilterExpression expAddress3 = new RadFilterContainsFilterExpression("ContactTitle");
        RadFilterContainsFilterExpression expCity = new RadFilterContainsFilterExpression("Address");
        RadFilterContainsFilterExpression expCountry = new RadFilterContainsFilterExpression("PostalCode");
        RadFilterContainsFilterExpression expCountry2 = new RadFilterContainsFilterExpression("CustomerID");


        // Clear filter if there was one before and then add a GroupOperation
        RadFilter1.RootGroup.Expressions.Clear();
        RadFilter1.RootGroup.GroupOperation = RadFilterGroupOperation.Or;

        // Add expressions to the RadFilter
        RadFilter1.RootGroup.AddExpression(expAddress1);
        RadFilter1.RootGroup.AddExpression(expAddress2);
        RadFilter1.RootGroup.AddExpression(expAddress3);
        RadFilter1.RootGroup.AddExpression(expCity);
        RadFilter1.RootGroup.AddExpression(expCountry);
        RadFilter1.RootGroup.AddExpression(expCountry2);
 

        // Values for all expressions come from the same input textbox
        expAddress1.Value = filterTextBox.Text;
        expAddress2.Value = filterTextBox.Text;
        expAddress3.Value = filterTextBox.Text;
        expCity.Value = filterTextBox.Text;
        expCountry.Value = filterTextBox.Text;
        expCountry2.Value = filterTextBox.Text;

        // Apply the filtered data to the RadGrid
        RadFilter1.RecreateControl();
        //RadFilter1.Visible = false;
        RadFilter1.FireApplyCommand();
       
        //RadGrid1.DataBind();
        //RadGrid1.MasterTableView.FilterExpression = string.Format("([CustomerID] LIKE '%{0}%')", filterTextBox.Text);
        RadGrid1.Rebind();
    }
}
