using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Telerik.Web.UI;
using System.Data.SqlClient;

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

    }

    protected void RadComboBox1_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
    {
        string sql = "SELECT [SupplierID], [CompanyName], [ContactName], [City] FROM [Suppliers]  WHERE CompanyName LIKE @CompanyName + '%'";
        SqlDataAdapter adapter = new SqlDataAdapter(sql,
            ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        adapter.SelectCommand.Parameters.AddWithValue("@CompanyName", e.Text);

        DataTable dt = new DataTable();
        adapter.Fill(dt);

        RadComboBox comboBox = (RadComboBox)sender;
        // Clear the default Item that has been re-created from ViewState at this point.
        comboBox.Items.Clear();

        foreach (DataRow row in dt.Rows)
        {
            RadComboBoxItem item = new RadComboBoxItem();
            item.Text = row["CompanyName"].ToString();
            item.Value = row["SupplierID"].ToString();
            item.Attributes.Add("ContactName", row["ContactName"].ToString());

            comboBox.Items.Add(item);

            item.DataBind();
        }
    }

    protected void RadComboBox2_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
    {
        string sql = "SELECT * FROM [Suppliers]  WHERE ContactName LIKE @ContactName + '%'";
        SqlDataAdapter adapter = new SqlDataAdapter(sql,
            ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        adapter.SelectCommand.Parameters.AddWithValue("@ContactName", e.Text);

        DataTable dt = new DataTable();
        adapter.Fill(dt);

        RadComboBox comboBox = (RadComboBox)sender;
        // Clear the default Item that has been re-created from ViewState at this point.
        comboBox.Items.Clear();

        foreach (DataRow row in dt.Rows)
        {
            RadComboBoxItem item = new RadComboBoxItem();
            item.Text = row["ContactName"].ToString();
            item.Value = row["SupplierID"].ToString();
            item.Attributes.Add("ContactName", row["ContactName"].ToString());

            comboBox.Items.Add(item);

            item.DataBind();
        }
    }

    protected void OnSelectedIndexChangedHandler(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        Session["SupplierID"] = e.Value;
    }

    protected void RadComboBox2_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        Session["ContactName"] = e.Value;
    }
}
