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 Page_Load(object sender, EventArgs e)
        {
            RadComboBox ddlControl = new RadComboBox();
            ddlControl.ItemTemplate = new TemplateProcessor();
            ddlControl.ID = "Testddl";
            for (int i = 0; i < 10; i++)
            {
                string strText = i.ToString();
                string strValue = (i * 2).ToString();
                ddlControl.Items.Add(new RadComboBoxItem(strValue, strText));
            }
            TemplateProcessor template = new TemplateProcessor();


            ddlControl.DataBind();

            ddlControl.EnableViewState = false;
            ddlControl.HighlightTemplatedItems = true;
            ddlControl.AllowCustomText = true;
            ddlControl.MarkFirstMatch = true;
            ddlControl.CollapseAnimation.Duration = 200;
            ddlControl.ExpandAnimation.Duration = 200;
            this.Form.Controls.Add(ddlControl);
        }
        public class TemplateProcessor : ITemplate
        {
            public void InstantiateIn(Control container)
            {
                Label label1 = new Label();
                label1.ID = "ItemLabel";
                label1.Text = "Text";
                label1.Font.Size = 11;
                label1.DataBinding += new EventHandler(label1_DataBinding);
                container.Controls.Add(label1);
            }
            private void label1_DataBinding(object sender, EventArgs e)
            {
                Label target = (Label)sender;
                RadComboBoxItem item = (RadComboBoxItem)target.BindingContainer;
                string itemText = (string)DataBinder.Eval(item, "Value");
                target.Text = itemText;
                RadComboBox combo = item.ComboBoxParent;
              //  combo.Text = itemText;
            }
        }


    }
}
