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

Export to Pdf issue when using Template Columns Programmatically

5 Answers 180 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Pooya
Top achievements
Rank 1
Pooya asked on 17 Jun 2011, 04:10 PM
I have a RadGrid with template columns which are generated at runtime and added to a placeholder control on Page_Init.

Export to Excel and Word work fine using the built-in export features. Export to Pdf doesn't work properly in the sense that the template columns are not exported in the final pdf file. Only the GridBoundColumns are exported.

I have also set ExportOnlyData = false but didn't fix that issue.

Any clues?

Thanks,

5 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 17 Jun 2011, 04:25 PM
Hello Pooya,

What is rendered in this template? Can you post the output HTML? Note that if you are using tables you have to add colgroup/col elements and width in absolute units as explained in this topic:
PDF export

Regards,
Daniel
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Pooya
Top achievements
Rank 1
answered on 17 Jun 2011, 04:34 PM
Thanks; yes.

Each template column is a table with 2 rows and 1-4 columns (depending on what parameter is passed I'm regenerating the RadGrid dynamically).

The html which is rendered in the header is like this:

<th class="rgHeader" scope="col"><table style="width: 100%; border-collapse: collapse;" cellSpacing="0" cellPadding="0">
<tbody><tr>
<td colSpan="2" align="center">MONDAY</td>
</tr><tr>
<td style="width: 50%;">AM</td><td style="width: 50%;">PM</td>
</tr>
</tbody></table>
</th>

That's generated by adding an ASP.NET Table control to the container object of the InstantiateIn() method when ITemplate is implemented.
0
Daniel
Telerik team
answered on 22 Jun 2011, 08:17 PM
Hello Pooya,

The table should be rendered as explained in the help topic otherwise RadGrid won't export it. You can make your own class that inherits the asp.net table and modify the rendering so that it adds colgroup/col elements. Sample code:
public class MyTable : Table
{
    public override void RenderBeginTag(HtmlTextWriter writer)
    {
        base.RenderBeginTag(writer);
        int cells = this.Rows[0].Cells.Count;
        StringBuilder outputString = new StringBuilder("<colgroup>");
        for (int colel = 0; colel < cells; colel++)
            outputString.Append("<col/>");
        outputString.Append("</colgroup>");
        writer.Write(outputString.ToString());
    }
}

Regards,
Daniel
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Pooya
Top achievements
Rank 1
answered on 23 Jun 2011, 10:00 AM
Great, thanks that problem is sorted.

How would it be possible to set a CSS style programmatically for the GridBoundColumns and TemplateColumns?

The texts appearing too big at the moment and don't fit the page.

Thanks
0
Daniel
Telerik team
answered on 28 Jun 2011, 04:15 PM
Hello Pooya,

You can use ItemCreated/ItemDataBound events to set the desired CSS styles on the target items/cells:

bool isExport = false;
protected void Button1_Click(object sender, EventArgs e)
{
    isExport = true;
    RadGrid1.MasterTableView.ExportToPdf();
}
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem && isExport)
        e.Item.Style["background-color"] = "#888888";
}

For more information, please examine the following links:
Export to PDF
PDF export

Kind regards,
Daniel
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
Pooya
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Pooya
Top achievements
Rank 1
Share this question
or