I am trying to use ExportToPdf to generate a .pdf document from a RadGrid. Here's a simplified version of my grid. The labels export to the .pdf, but the table with "TGIF" does not. I need to use HTML formatting to arrange the labels. What am I doing wrong? Thanks!
<telerik:RadGrid ID="gridTest" runat="server" AutoGenerateColumns="False"
Skin="Default" Width="800px"
OnItemCreated="gridTest_ItemCreated" >
<ExportSettings
IgnorePaging="true" OpenInNewWindow="true" ExportOnlyData="False">
<Pdf PaperSize="Letter"></Pdf>
</ExportSettings>
<MasterTableView ShowHeader="false">
<Columns>
<telerik:GridTemplateColumn DataField="strCaseID" UniqueName="strCaseID" ShowFilterIcon="false" >
<ItemTemplate>
<table>
<tr>
<td>
TGIF!
</td>
</tr>
</table>
<asp:Label ID="lbName" runat="server" Text='<%#Eval("strEmployeeFName")%>' ></asp:Label><br />
<asp:Label ID="lbAddressStreet1" runat="server" Text='<%#Eval("strEmployeeAddressStreet1")%>' ></asp:Label><br />
<asp:Label ID="lbAddressStreet2" runat="server" Text='<%#Eval("strEmployeeAddressStreet2")%>' ></asp:Label><br />
<asp:Label ID="lbAddressCity" runat="server" Text='<%#Eval("strEmployeeAddressCity")%>' ></asp:Label><br />
<asp:Label ID="lbAddressState" runat="server" Text='<%#Eval("strEmployeeAddressState")%>' ></asp:Label><br />
<asp:Label ID="lbAddressZip" runat="server" Text='<%#Eval("strEmployeeAddressZip")%>' ></asp:Label><br />
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
in Page_Load...
PopulateGrid(gridTest);
ConfigureGridBeforeExportToPdf();
gridTest.MasterTableView.ExportToPdf();
protected void gridTest_ItemCreated(object sender, GridItemEventArgs e)
{
try
{
ConfigureGridItem(e.Item);
}
catch (Exception ex)
{
// do stuff
}
}
protected void ConfigureGridItem(GridItem item)
{
// ***** THIS IS FOR - each Item
item.Style["color"] = "purple"; // font color
if (item is GridHeaderItem)
{
item.Visible = false;
}
else if (item is GridDataItem)
{
item.Style["vertical-align"] = "middle";
item.Style["text-align"] = "left";
}
switch (item.ItemType)
{
case GridItemType.Item: item.Style["background-color"] = "lightyellow"; break;
case GridItemType.AlternatingItem: item.Style["background-color"] = "mistyrose"; break;
}
}
public void ConfigureGridBeforeExportToPdf()
{
// ***** THIS IS FOR - entire Grid
// format - Pdf Settings
gridTest.ExportSettings.Pdf.BorderType = GridPdfSettings.GridPdfBorderType.OuterBorders;
gridTest.ExportSettings.Pdf.BorderStyle = GridPdfSettings.GridPdfBorderStyle.Thick;
gridTest.ExportSettings.Pdf.BorderColor = System.Drawing.Color.HotPink;
gridTest.ExportSettings.Pdf.PaperSize = GridPaperSize.Letter;
gridTest.ExportSettings.Pdf.PageHeight = Unit.Parse("162mm");
gridTest.ExportSettings.Pdf.PageWidth = Unit.Parse("600mm");
// format - header
GridItem headerItem = gridTest.MasterTableView.GetItems(GridItemType.Header)[0];
headerItem.Visible = false;
// format - footer
gridTest.ExportSettings.Pdf.PageFooter.MiddleCell.Text = "<?page-number?>";
gridTest.ExportSettings.Pdf.PageFooter.MiddleCell.TextAlign = GridPdfPageHeaderFooterCell.CellTextAlign.Center;
}