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

Export to Excel in Hierarchial RadGrid

1 Answer 67 Views
Grid
This is a migrated thread and some comments may be shown as answers.
unnati
Top achievements
Rank 1
unnati asked on 08 Jun 2011, 12:11 PM
Hello Telerik Team,

I have developed a Hierarchial RadGrid using the approach given here:
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/detailtabledatabind/defaultcs.aspx

Then added 'Export to Excel' functionality to the grid.
The code for the same is given here.

There are 2 issues with 'Export to Excel' functionality
1. 'Export to Excel' button when clicked first time works fine. But when I click it again, it does not work.
2. Data is exported only for the first level, not for the hierarchy tables.

<asp:Button runat="server" ID="Button1" OnClick="Button1_Click" Text="Export to Excel" />
protected void Button1_Click(object sender, EventArgs e)
       {
           ConfigureExport();
            
           RadGrid1.MasterTableView.ExportToExcel();
       }
       public void ConfigureExport()
       {
           RadGrid1.ExportSettings.ExportOnlyData = true;
 
       }
Please provide solution asap

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 08 Jun 2011, 01:28 PM
Hello Unnati,

I am not quite sure about your first scenario. I suppose this issue arises because of using SimpleDataBinding. In order to implement advanced features, use AdvancedDataBinding.

For second scenario, try setting HierarchyDefaultExpanded as true and then export.

C#:
protected void Export_Excel_Click(object sender, System.EventArgs e)
    {
        RadGrid2.MasterTableView.HierarchyDefaultExpanded = true;
        RadGrid2.ExportSettings.IgnorePaging = true;
        RadGrid2.ExportSettings.OpenInNewWindow = true;  
        RadGrid2.MasterTableView.HierarchyDefaultExpanded = true;
        RadGrid2.ExportSettings.ExportOnlyData = true;
        RadGrid2.MasterTableView.ExportToExcel();
    }

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