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 ProductsGrid_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
    {
        RadGrid thisGrid = source as RadGrid;
        GridNestedViewItem nestedItem = thisGrid.NamingContainer as GridNestedViewItem;
        GridDataItem parentItem = nestedItem.ParentItem;
        string dataKeyValue = parentItem.GetDataKeyValue("CategoryID").ToString();

        if (parentItem.Expanded)
        {
            ProductsDataSource.SelectParameters["CategoryID"].DefaultValue = dataKeyValue;
            
        }
        else
        {
            thisGrid.ShowHeader = false;
            ProductsDataSource.SelectParameters["CategoryID"].DefaultValue = "-1";
        }

        thisGrid.DataSource = ProductsDataSource.Select(new DataSourceSelectArguments());
    }
}
