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

add multiple radgrids dynamically to a wrapper radgrid and export to PDF

2 Answers 75 Views
Grid
This is a migrated thread and some comments may be shown as answers.
libni
Top achievements
Rank 1
libni asked on 26 Mar 2019, 02:06 PM
I want to export 2 RadGrids to PDF the RadGrid's inbuilt exporting feature. I have a wrapper Grid. The Grids that I want to export are located at different of my UI, so I don't want to add the grids directly in the wrapper grid. On the Export button click, I want to add the the Wrapper grid and export to PDF.  I just want both grids to be on a single PDF file. it's okay for me convert the first child grid(data filter details) to a string of text, with new lines, and place on the top of the PDF export of the second (bigger data grid), for this also I couldn't find a way. I have a sample code, but since I am new to the forum, I couldn't find an easy way to copy it here. I will do it as soon as I can. Thanks in advance.

2 Answers, 1 is accepted

Sort by
0
libni
Top achievements
Rank 1
answered on 26 Mar 2019, 02:30 PM
<form runat="server">
    <asp:ScriptManager ID="sm" runat="server"></asp:ScriptManager>
    <telerik:RadButton ID="btnExportToPDF" runat="server" Text="Export To PDF" OnClick="btnExportToPDF_Click"></telerik:RadButton>
 
    <telerik:RadGrid ID="grdEmployees" runat="server" OnNeedDataSource="grdEmployees_NeedDataSource">
        <MasterTableView AutoGenerateColumns="true">
        </MasterTableView>
    </telerik:RadGrid>
    <telerik:RadGrid ID="grdDepartments" runat="server" OnNeedDataSource="grdDepartments_NeedDataSource">
        <MasterTableView AutoGenerateColumns="true">
        </MasterTableView>
    </telerik:RadGrid>
 
 
    <telerik:RadGrid ID="grdMyWrapper" runat="server" ShowHeader="false" Width="550px" BorderStyle="None" OnItemCreated="RadGridWrapper_ItemCreated" Visible="true">
        <ExportSettings OpenInNewWindow="true" ExportOnlyData="false" />
        <MasterTableView AutoGenerateColumns="true" BorderStyle="None">
            <ItemTemplate>
            </ItemTemplate>
        </MasterTableView>
    </telerik:RadGrid>
</form>

 

protected void RadGridWrapper_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridHeaderItem) e.Item.Visible = false;
}
 
protected void btnExportToPDF_Click(object sender, EventArgs e)
{
    grdMyWrapper.Items[0].Cells[0].Controls.Add(grdEmployees);
    grdMyWrapper.Items[0].Cells[0].Controls.Add(grdDepartments);
     grdMyWrapper.ExportToPdf();
}

 

Even alternative ways to achieve would be a great help. Thanks.

0
Attila Antal
Telerik team
answered on 29 Mar 2019, 01:07 PM
Hi Libni,

We have a code-library sample which I would recommend for this scenario. That sample shows the way to export multiple Grids to PDF and even for Excel at Export multiple RadGrids in single PDF/Excel file. Please check it out and see if that works for you.

For more details about the PDF Export functionality, you can check out the PDF Export article, and also the Questions and Answers section of it.

Kind regards,
Attila Antal
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
libni
Top achievements
Rank 1
Answers by
libni
Top achievements
Rank 1
Attila Antal
Telerik team
Share this question
or