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_Load(object sender, EventArgs e)
    {

    }



    protected void RadGrid1_PreRender(object sender, EventArgs e)
    {

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        if (RadGrid1.SelectedItems.Count != 0)
        {
            foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
            {
                if (!item.Selected)
                    item.Visible = false;
            }
        }
        HideInHierarchyRecursive(RadGrid1.MasterTableView);
        RadGrid1.ExportSettings.OpenInNewWindow = true;
        RadGrid1.ExportSettings.ExportOnlyData = true;
        RadGrid1.MasterTableView.ExportToExcel();
    }


    void HideInHierarchyRecursive(GridTableView gridTableView)
    {
        foreach (GridNestedViewItem nestedViewItem in gridTableView.GetItems(GridItemType.NestedView))
        {
            if (nestedViewItem.NestedTableViews.Length > 0)
            {
                foreach (GridDataItem item in nestedViewItem.NestedTableViews[0].Items)
                {
                    if (!item.Selected)
                        item.Visible = false;
                }
                HideInHierarchyRecursive(nestedViewItem.NestedTableViews[0]);
            }
        }
    }
}
