using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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

public partial class Default : System.Web.UI.Page 
{
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        RadGrid1.ItemCommand += new GridCommandEventHandler(RadGrid1_ItemCommand);
        RadGrid1.InsertCommand += new GridCommandEventHandler(RadGrid1_InsertCommand);
    }

    void RadGrid1_InsertCommand(object source, GridCommandEventArgs e)
    {
        if (e.Item is GridEditFormInsertItem)
        {
            GridEditFormInsertItem item = e.Item as GridEditFormInsertItem;
            string parentID = ((GridNestedViewItem)(e.Item.OwnerTableView.NamingContainer)).ParentItem.GetDataKeyValue("CustomerID").ToString();
            RadAjaxManager1.Alert(string.Format("Parent ID is: {0}", parentID));
        }
    }

    void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
    {
        if (e.CommandName == "book")
        {
            e.Canceled = true;
            e.Item.OwnerTableView.EditFormSettings.EditFormType = GridEditFormType.WebUserControl;
            e.Item.OwnerTableView.EditFormSettings.UserControlName = "/insert_usage_form.ascx";
            e.Item.OwnerTableView.InsertItem();
        }
    }
}
