using System;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI;
using System.IO;
using System.Web.UI.WebControls;
using Telerik.QuickStart;
using Telerik.Web.UI;
using System.Configuration;

namespace Telerik.ComboboxExamplesCS.MultiColumnCombo
{
	public partial class DefaultCS: XhtmlPage
	{
        protected void RadComboBox1_DataBound(object sender, EventArgs e)
        {
            ((Label)RadComboBox1.Footer.FindControl("RadComboItemsCount")).Text = Convert.ToString(RadComboBox1.Items.Count);
        }

		protected void RadComboBox1_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
		{		
			string sql = "SELECT * from Customers WHERE CompanyName LIKE '" + e.Text + "%'";
			SqlDataAdapter adapter = new SqlDataAdapter(sql,
				ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString);
            
			DataTable dt = new DataTable();
			adapter.Fill(dt);
			
			RadComboBox comboBox = (RadComboBox)sender;
            
			RadComboBox1.DataSourceID = "";
			RadComboBox1.DataSource = dt;
            RadComboBox1.DataBind();
		}

		protected void Button1_Click(object sender, System.EventArgs e)
		{
			Label1.Text = "You selected: <b>" + RadComboBox1.Text + "</b>";
		}

		protected void RadComboBox1_ItemDataBound(object sender, RadComboBoxItemEventArgs e)
		{
            e.Item.Text = ((DataRowView)e.Item.DataItem)["CompanyName"].ToString() + "; " + ((DataRowView)e.Item.DataItem)["City"].ToString() + "; " + ((DataRowView)e.Item.DataItem)["ContactTitle"].ToString();
            e.Item.Value = ((DataRowView)e.Item.DataItem)["CompanyName"].ToString() + "; " + ((DataRowView)e.Item.DataItem)["City"].ToString() + "; " + ((DataRowView)e.Item.DataItem)["ContactTitle"].ToString();
            
            //Image img = e.Item.FindControl("image1") as Image;
            //if (DateTime.Now.Millisecond % 3 == 0)
            //    img.Visible = true;
        }

	}
}
