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

Exporting multiple grids to pdf

3 Answers 189 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gama
Top achievements
Rank 1
Gama asked on 12 Mar 2012, 08:48 PM
I've pretty much kept to the example here
http://www.telerik.com/community/code-library/aspnet-ajax/grid/export-multiple-radgrids-in-single-pdf-excel-file.aspx

except that I have two grids on separate rows, which I've done like this.

<telerik:RadGrid ID="rgridExport" AutoGenerateColumns="false" runat="server" OnNeedDataSource="rgridExport_NeedDataSource" ExportSettings-ExportOnlyData="false"
    ExportSettings-OpenInNewWindow="true" OnItemDataBound="rgridExport_ItemDataBound" ShowHeader="false" AlternatingItemStyle-BackColor="White">
        <MasterTableView>
            <Columns>
                <telerik:GridBoundColumn UniqueName="Id" DataField="Id" Visible="false" />
                <telerik:GridTemplateColumn UniqueName="image">
                     
                    <ItemTemplate>
                    <table width="100%">
                        <tr>
                            <td align="right" valign="middle" style="vertical-align:middle; width:50px;">
                            <asp:Image runat="server" ID="img" />
                           </td>
                           <td>
                        <telerik:RadGrid ID="rgrid" runat="server" Skin="Sitefinity" ItemStyle-HorizontalAlign="Center" AlternatingItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" >
                            <ExportSettings ExportOnlyData="true" OpenInNewWindow="true" />
                        </telerik:RadGrid>
                           </td>
                        </tr>
                    </table>
                    <br /><br /><br />
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
                     
            </Columns>
        </MasterTableView>
         
    </telerik:RadGrid>
and the .cs file
protected void rgridExport_NeedDataSource(object sender, EventArgs e)
{
    DataTable dt = new DataTable();
    dt.Columns.Add("Id", typeof(int));
    DataRow dr = dt.NewRow();
    dr["Id"] = 1;
    dt.Rows.Add(dr);
    dr = dt.NewRow();
    dr["Id"] = 2;
    dt.Rows.Add(dr);
    rgridExport.DataSource = dt;
  
}
protected void rgridExport_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem item = (GridDataItem)e.Item;
        Image img = item["image"].FindControl("img") as Image;
        RadGrid rgrid = item["image"].FindControl("rgrid") as RadGrid;
  
        switch (item["Id"].Text)
        {
            case "1":
                rgrid.ShowFooter = true;
                rgrid.GridLines = GridLines.Horizontal;
                rgrid.AllowPaging = true;
                rgrid.AutoGenerateColumns = false;
                rgrid.NeedDataSource += rgHitRatio_NeedDataSource;
                rgrid.ItemDataBound += rgHitRatio_ItemDataBound;
                rgrid.MasterTableView.ShowFooter = true;
                rgrid.FooterStyle.Font.Bold = true;
                GridBoundColumn col = new GridBoundColumn();
                col.UniqueName = "Placed";
                col.HeaderText = "Placed";
                col.DataField = "Placed";
                rgrid.Columns.Add(col);
                col = new GridBoundColumn();
                col.UniqueName = "#";
                col.HeaderText = "#";
                col.DataField = "#";
                col.Aggregate = GridAggregateFunction.Sum;
                col.FooterAggregateFormatString = "{0}";
                rgrid.Columns.Add(col);
                col = new GridBoundColumn();
                col.UniqueName = "30";
                col.HeaderText = "30";
                col.DataField = "30";
                col.Aggregate = GridAggregateFunction.Sum;
                col.FooterAggregateFormatString = "{0}";
                rgrid.Columns.Add(col);
                col = new GridBoundColumn();
                col.UniqueName = "60";
                col.HeaderText = "60";
                col.DataField = "60";
                col.Aggregate = GridAggregateFunction.Sum;
                col.FooterAggregateFormatString = "{0}";
                rgrid.Columns.Add(col);
                col = new GridBoundColumn();
                col.UniqueName = "90";
                col.HeaderText = "90";
                col.DataField = "90";
                col.Aggregate = GridAggregateFunction.Sum;
                col.FooterAggregateFormatString = "{0}";
                rgrid.Columns.Add(col);
                col = new GridBoundColumn();
                col.UniqueName = "Total";
                col.HeaderText = "Total";
                col.DataField = "Total";
                col.Aggregate = GridAggregateFunction.Sum;
                col.FooterAggregateFormatString = "{0}";
                rgrid.Columns.Add(col);
                col = new GridBoundColumn();
                col.UniqueName = "Exhausted";
                col.HeaderText = "Exhausted";
                col.DataField = "Exhausted";
                col.Aggregate = GridAggregateFunction.Sum;
                col.FooterAggregateFormatString = "{0}";
                rgrid.Columns.Add(col);
                col = new GridBoundColumn();
                col.UniqueName = "Rate";
                col.HeaderText = "Rate";
                col.DataField = "Rate";
                col.Aggregate = GridAggregateFunction.Custom;
                col.DataType = typeof(double);
                col.FooterAggregateFormatString = "{0:N2}%";
                col.DataFormatString = "{0:N2}%";
                rgrid.Columns.Add(col);
  
                img.ImageUrl = "~/Images/Clients/Summary.png";
                break;
            case "2":
                rgrid.NeedDataSource += rgScoreCard_NeedDataSource;
                img.ImageUrl = "~/Images/Clients/scorecard.png";
                break;
                  
        }
        if(rgrid != null)
            rgrid.Rebind();
    }
}
protected void btnExport_Click(object sender, EventArgs e)
{
    rgridExport.MasterTableView.ExportToPdf();
}

On the screen, it looks fine, but when I export, I just get empty boxes (see attached)

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 15 Mar 2012, 10:44 AM
Hello Gama,

Please open the PDF export help topic and examine the Exporting HTML tables section.
Let me know if you need more information.

Regards,
Daniel
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Gama
Top achievements
Rank 1
answered on 19 Mar 2012, 07:14 PM
Adding the colgroup and a static width mostly fixed it, but headers are now missing from my top grid.  As you can see from my code above, I build the top grid in code behind, but the botton has autmatically generated columns.  Only the one with auto generated columns has column headers.
0
Daniel
Telerik team
answered on 22 Mar 2012, 01:36 PM
Hi,

This might happen if you are trying to export an invisible RadGrid. If this is the case, you have to set it Visible="true" beforehand.

Regards,
Daniel
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Gama
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Gama
Top achievements
Rank 1
Share this question
or