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

namespace Telerik.ComboboxExamplesCS.ComboInGrid
{
	public partial class DefaultCS : Page
	{
		protected void RadComboBox1_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
		{
            RadComboBox RadComboBox1 = (RadComboBox)sender;

            string sql = "SELECT * from Customers";

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

            try
            {

                int itemsPerRequest = 10;
                int itemOffset = e.NumberOfItems;
                int endOffset = itemOffset + itemsPerRequest;
                if (endOffset > data.Rows.Count)
                {
                    endOffset = data.Rows.Count;
                }
                if (endOffset == data.Rows.Count)
                {
                    e.EndOfItems = true;
                }
                else
                {
                    e.EndOfItems = false;
                }
                for (int i = itemOffset; i < endOffset; i++)
                {
                    RadComboBox1.Items.Add(new RadComboBoxItem(data.Rows[i]["CompanyName"].ToString(), data.Rows[i]["CompanyName"].ToString()));
                }

                if (data.Rows.Count > 0)
                {
                    e.Message = String.Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>", endOffset.ToString(), data.Rows.Count.ToString());
                }
                else
                {
                    e.Message = "No matches";
                }
            }
            catch
            {
                e.Message = "No matches";
            }

		}
	}
}
