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

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

    }


    protected void RadComboBox1_SelectedIndexChanged(object o, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
    {

    }
    protected void RadCboCategories_ItemsRequested(object o, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e)
    {
        LoadCategories(e.Text);
    }

    protected void RadCboCategories_SelectedIndexChanged(object o, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
    {
        string CategoryID = RadCboCategories.SelectedValue.Trim();
        //Loadlable(CategoryID);

        DataTable dt = new DataTable();
        string sql = "Select * from Categories where CategoryID= " + CategoryID;
        SqlDataAdapter adapter = new SqlDataAdapter(sql,
            ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString);
        adapter.Fill(dt);

        lblCategoryName.Text = dt.Rows[0][2].ToString();
    }

    private void LoadCategories(string filter)
    {
        string sql = "select * from Categories";

        if (filter != String.Empty)
        {
            sql += " where CategoryName LIKE '%" + filter.Replace("'", "''") + "%'";
        }

        SqlDataAdapter adapter = new SqlDataAdapter(sql,
            ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString);

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

        RadCboCategories.DataSource = dt;
        RadCboCategories.DataBind();

    }

    public void Loadlable(string khoa)
    {
        DataTable dt = new DataTable();
        string sql = "Select * from Categories where CategoryID= " + khoa;
        SqlDataAdapter adapter = new SqlDataAdapter(sql,
            ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString);
        adapter.Fill(dt);

        lblCategoryName.Text = dt.Rows[0][2].ToString();
    }
}
