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

public partial class RadGridDataTable : System.Web.UI.Page
{
    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 Page_Load(object sender, EventArgs e)
    {
    }

    protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
    {
        string selectQuery = "SELECT [OrderID], [ProductID], [UnitPrice], [Quantity], [Discount] FROM [Order Details]";

        RadGrid1.DataSource = GetDataTable(selectQuery);
    }
   
    protected void RadCombobox1_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        string selectQuery = "SELECT [OrderID], [ProductID], [UnitPrice] FROM [Order Details]";

        RadGrid1.DataSource = GetDataTable(selectQuery);

        RadGrid1.Rebind();
    }
}