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;
using System.Reflection;
using System.Drawing;

public partial class _Default : System.Web.UI.Page
{
    public static Random rand = new Random();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Assembly.GetAssembly(typeof(ScriptManager)).FullName.IndexOf("3.5") != -1)
        {
            RadGrid1.MasterTableView.FilterExpression = "it.Category == \"\"";
        }
        else
        {
            RadGrid1.MasterTableView.FilterExpression = "([Category] <> '')";
        }
    }

    protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
    {
        RadGrid1.DataSource = Data;
    }

    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridHeaderItem && e.Item.OwnerTableView != RadGrid1.MasterTableView)
        {
            e.Item.Style["display"] = "none";
        }

        if (e.Item is GridNoRecordsItem)
        {
            GridNoRecordsItem item = e.Item as GridNoRecordsItem;
            item.OwnerTableView.Style["display"] = "none";
            item.OwnerTableView.ParentItem.Expanded = false;
            (item.OwnerTableView.ParentItem["ExpandColumn"].Controls[0] as Button).Visible = false;
            item.OwnerTableView.ParentItem.Style["background-color"] = "beige"; //items in beige should not be visible on first level
        }
    }

    private List<fooMetrics> Data
    {
        get
        {
            if (!Page.IsPostBack)
            {
                List<fooMetrics> data = new List<fooMetrics>();
                data.Add(new fooMetrics() { Metric = "Parent", CurrentValue = "82", PreviousValue = "26", Change = "-12%", Category = "" });
                data.Add(new fooMetrics() { Metric = "Child 1", CurrentValue = "$293", PreviousValue = "300", Change = "-12%", Category = "Parent" });
                data.Add(new fooMetrics() { Metric = "Child 2", CurrentValue = "$293", PreviousValue = "300", Change = "-12%", Category = "Parent" });

                Session["_data"] = data;
            }

            return (List<fooMetrics>)Session["_data"];
        }
    }
}

class fooMetrics
{
    public string Metric { get; set; }
    public string CurrentValue { get; set; }
    public string PreviousValue { get; set; }
    public string Change { get; set; }
    public string Category { get; set; }
}
