using System;
using System.Linq;
using System.Data;
using Telerik.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

        RadGrid1.NeedDataSource += new Telerik.Web.UI.GridNeedDataSourceEventHandler(RadGrid1_NeedDataSource);
        RadGrid1.ItemCreated += RadGrid1_ItemCreated;
    }

    private void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
            GridDataItem gridDataItem = (GridDataItem)e.Item;
            Button btnAdd = (Button)gridDataItem["MytemplateColumn"].FindControl("Button1");
            string id = gridDataItem.GetDataKeyValue("ID").ToString();
            btnAdd.Attributes["onclick"] = string.Format("btnAddClick('{0}'); return false;", id);   
        }
    }

    void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
    {
        DataTable table = new DataTable();
        table.Columns.Add("ID");
        table.Columns.Add("Item");
        table.Columns.Add("Date", typeof(DateTime));
        for (int i = 1; i < 8; i++)
        {
            table.Rows.Add(i, "Item" + i.ToString(), DateTime.Now.AddDays(i));
        }

        RadGrid1.DataSource = table;
    }
}
