using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Telerik.Web.UI;
using System.Collections.Generic;

public partial class _Default : System.Web.UI.Page 
{
    private MyTemplate HeaderTemplate1 = new MyTemplate();
    private MyTemplate ItemTemplate1 = new MyTemplate();

    protected void Page_Load(object sender, EventArgs e)
    {
        this.RefreshHeaderTemplate();
    }

    protected void OnAddButton_Click(object sender, EventArgs e)
    {
        //Configure Template based on different values, depending on your scenario...
        HeaderTemplate1.CheckBox.Checked = true;
        HeaderTemplate1.CheckBox.Enabled = false;
        HeaderTemplate1.TextBox.Visible = true;
        HeaderTemplate1.TextBox.Enabled = false;

        Button button = new Button();
        button.Text = "newly added button";

        HeaderTemplate1.AddControl(button);

        this.RadComboBox1.HeaderTemplate = HeaderTemplate1;
    }

    protected void OnRefresh_Click(object sender, EventArgs e)
    {
        this.RefreshHeaderTemplate();
    }

    private void RefreshHeaderTemplate()
    {
        //Configure Template based on different values, depending on your scenario...
        HeaderTemplate1.CheckBox.Checked = DateTime.Now.Second % 2 > 0 ? true : false;
        HeaderTemplate1.CheckBox.Enabled = (DateTime.Now.Second + 1) % 2 > 0 ? true : false;
        HeaderTemplate1.TextBox.Visible = (DateTime.Now.Second) % 3 > 0 ? true : false;
        HeaderTemplate1.TextBox.Enabled = (DateTime.Now.Second + 1) % 3 > 0 ? true : false;

        this.RadComboBox1.HeaderTemplate = HeaderTemplate1;
    }
}

internal class MyTemplate : ITemplate
{
    private CheckBox CheckBox1;
    private TextBox TextBox1;
    private List<Control> Controls1;

    public TextBox TextBox
    {
        get { return this.TextBox1; }
    }

    public CheckBox CheckBox
    {
        get { return this.CheckBox1; }
    }

    public MyTemplate()
    {
        this.CheckBox1 = new CheckBox();
        this.TextBox1 = new TextBox();
        this.Controls1 = new List<Control>();

        this.TextBox1.DataBinding += new EventHandler(TextBox1_DataBinding);
    }

    public MyTemplate(bool checkBoxChecked, string textBoxValue)
        : this()
    {
        this.CheckBox1.Checked = checkBoxChecked;
        this.TextBox1.Text = textBoxValue;
    }

    public void AddControl(Control control)
    {
        this.Controls1.Add(control);
    }

    public void InstantiateIn(Control container)
    {
        container.Controls.Add(this.CheckBox1);
        container.Controls.Add(this.TextBox1);

        foreach (Control control in this.Controls1)
        {
            container.Controls.Add(control);
        }
    }

    protected void TextBox1_DataBinding(object sender, EventArgs e)
    {
        RadComboBoxItem item = (RadComboBoxItem)this.TextBox1.BindingContainer;

        this.TextBox1.Text = item.Value;
    }
}