This is a migrated thread and some comments may be shown as answers.

Hierarchical Grid, Collapse the Expand/Collapse column prior to export.

1 Answer 71 Views
Grid
This is a migrated thread and some comments may be shown as answers.
gc_0620
Top achievements
Rank 1
gc_0620 asked on 05 Nov 2010, 10:49 PM

Folks,

Using ASP.Net Ajax V2010 Release 2 with VStudio 2008 SP1.

We would like to collapse the expand/collapse column (if it is expanded) prior to export. Below is my command; basically prior to export, I would like to see if expand/collapse column is already expanded by user. If so collapse it 1st and then do export.
 
Thanks

protected void Export_Excel_Click(object sender, System.EventArgs e)
    {
        RadGrid1.MasterTableView.HierarchyDefaultExpanded = true;
        RadGrid1.ExportSettings.IgnorePaging = CheckBox2.Checked;
        RadGrid1.ExportSettings.OpenInNewWindow = true;     
        RadGrid1.ExportSettings.Excel.Format =  Telerik.Web.UI.GridExcelExportFormat.ExcelML;
  
        RadGrid1.ExportSettings.ExportOnlyData = true;
        RadGrid1.MasterTableView.ExportToExcel();
    }

 

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 08 Nov 2010, 05:31 AM
Hello,

The following code snippet will help you to achieve this. You can loop through each item and check whether it is expanded or not .If it is expanded, collapse it first and then export the grid.

C#:
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
   {
      if (e.CommandName == RadGrid.ExportToExcelCommandName )
       {
          foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
           {
               if (item.Expanded)// checking whether the item is expanded or not
                   item.Expanded = false;
           }
           RadGrid1.ExportSettings.OpenInNewWindow = true;
           RadGrid1.MasterTableView.ExportToExcel();
       }
   }

Thanks,
Princy.
Tags
Grid
Asked by
gc_0620
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or