using System;
using System.Data;
using Telerik.Web.UI;
using System.Data.SqlClient;
using System.Configuration;

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

	protected void RadComboBox1_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
	{

		if (e.Text.Length < 1)
		{
			SqlDataAdapter adapter = new SqlDataAdapter("SELECT * from CustomerPhotos",
			   ConfigurationManager.ConnectionStrings["TelerikConnectionString"].ConnectionString);

			DataTable data = new DataTable();
			adapter.Fill(data);
			Session["DtTemp"] = data;

			for (int i = 0; i < data.Rows.Count; i++)
			{
				RadComboBox1.Items.Add(new RadComboBoxItem(data.Rows[i]["CompanyName"].ToString(), data.Rows[i]["CompanyName"].ToString()));
			}
		}
		else
		{
			DataTable sessionData = new DataTable();
			sessionData = (DataTable)Session["DtTemp"];
			string exp = "CompanyName like '" + e.Text + "' + '%'";
			DataTable dt1 = new DataTable();
			dt1.Columns.Add("CompanyName", typeof(string));
			DataRow[] dr1 = sessionData.Select(exp);
			foreach (DataRow dRow in dr1)
			{
				DataRow dr = dt1.NewRow();
				dr["CompanyName"] = dRow["CompanyName"];
				dt1.Rows.Add(dr);
			}
			RadComboBox1.DataSource = dt1;
			RadComboBox1.DataTextField = "CompanyName";
			RadComboBox1.DataValueField = "CompanyName";
			RadComboBox1.DataBind();
		}
	}
}