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 RadGridComboBoxBoundWIthSQL : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    int count = -1;
    protected void RadComboBox1_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        count = int.Parse(e.Value);
        RadGrid1.Rebind();
    }
    protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        if (count >= 0)
        {
            RadGrid1.DataSource = GetDataTable("SELECT TOP " + count + "[OrderID], [OrderDate], [Freight], [ShipName], [ShipCountry] FROM [Orders]");
        }
    }
    private DataTable GetDataTable(string query)
    {
        string connString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
        SqlConnection conn = new SqlConnection(connString);
        SqlDataAdapter adapter = new SqlDataAdapter();
        SqlCommand command = new SqlCommand(query, conn);

        adapter.SelectCommand = command;
        DataTable myDataTable = new DataTable();

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

        return myDataTable;
    }

}