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;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        RadGrid1.ItemDataBound += new GridItemEventHandler(RadGrid1_ItemDataBound);
    }

    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
            GridDataItem item = e.Item as GridDataItem;
            Label CountLabel = item.FindControl("CountLabel") as Label;

        }
    }
    protected void RadGrid1_DetailTableDataBind(object source, Telerik.Web.UI.GridDetailTableDataBindEventArgs e)
    {
        GridDataItem dataItem = (GridDataItem)e.DetailTableView.ParentItem;

        switch (e.DetailTableView.Name)
        {
            case "Orders":
                {
                    string CustomerID = dataItem.GetDataKeyValue("CustomerID").ToString();
                    SqlDataSource2.SelectCommand = "SELECT * FROM Orders WHERE CustomerID = '" + CustomerID + "'";
                    e.DetailTableView.DataSource = SqlDataSource2.Select(new DataSourceSelectArguments());

                    GridDataItem item = e.DetailTableView.ParentItem as GridDataItem;
                    Label CountLabel = item.FindControl("CountLabel") as Label;
                    CountLabel.Text = ((DataView)e.DetailTableView.DataSource).Table.Rows.Count.ToString();
                    break;
                }
        }
    }

}