using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Init(object sender, EventArgs e)
    {
        RadGrid1.ItemCommand += new GridCommandEventHandler(RadGrid1_ItemCommand);
        RadGrid1.NeedDataSource += new GridNeedDataSourceEventHandler(RadGrid1_NeedDataSource);
        RadGrid1.ItemDataBound += new GridItemEventHandler(RadGrid1_ItemDataBound);
        RadGrid1.ItemCreated += new GridItemEventHandler(RadGrid1_ItemCreated);
        
        
    }

    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridEditableItem && e.Item.IsInEditMode)
        {
            GridEditableItem item = e.Item as GridEditableItem;
            RadComboBox combo = item["Supplier"].FindControl("rcmbSuppliers") as RadComboBox;
            combo.DataSource = SqlDataSource3.Select(new DataSourceSelectArguments());
        }

        if (e.Item is GridNestedViewItem)
        {
            RadGrid grid = e.Item.FindControl("RadGrid2") as RadGrid;
            grid.NeedDataSource += new GridNeedDataSourceEventHandler(grid_NeedDataSource);
        }
    }

    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {

    }

    protected void grid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        GridDataItem parentItem = ((GridNestedViewItem)(((RadGrid)sender).NamingContainer)).ParentItem;

        string parentID = parentItem.GetDataKeyValue("ProductID").ToString();

        ((RadGrid)sender).DataSource = Enumerable.Range(0, 10).Select(x => new { ID = x, ParentID = parentID });
    }

    protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        
    }

    protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {

    }

}
