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

Radgrid with export to pdf

3 Answers 204 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Vatsal
Top achievements
Rank 2
Vatsal asked on 04 Jun 2012, 01:03 PM
Hi,
I have one rad grid with export to pdf functionality. I have put one html table in item command template which contains, image, report name, generated datetime etc. I add this table which looks like report header. But when I click on export to pdf link in command item template, it does not export command item template data. If I remove table and write text direct into command item template than it works fine and I can see text from command item template to pdf. But I can't format header data without table so I can't remove table from command item template. Export to excel and word works fine.

Can any one help me in this? Columns in below grid are generating at run time.

<telerik:RadGrid ID="radGridReportData" runat="server" BorderStyle="None" GridLines="None"
        AutoGenerateColumns="false" ShowFooter="true" Width="1000px" AllowPaging="false"
        AllowSorting="true" AllowFilteringByColumn="true" AllowAutomaticUpdates="false"
        ShowGroupPanel="false" OnNeedDataSource="radGridReportData_NeedDataSource" OnItemCommand="radGridReportData_ItemCommand"
        OnItemCreated="radGridReportData_ItemCreated" OnItemDataBound="radGridReportData_ItemDataBound">
        <ExportSettings IgnorePaging="true" OpenInNewWindow="true">
            <Pdf PageHeight="210mm" PageWidth="297mm" PageBottomMargin="20mm" PageTopMargin="20mm"
                PageLeftMargin="20mm" PageRightMargin="20mm" />
        </ExportSettings>
        <ClientSettings AllowGroupExpandCollapse="True" ReorderColumnsOnClient="False" AllowDragToGroup="false"
            AllowColumnsReorder="False" EnableRowHoverStyle="True">
            <Selecting AllowRowSelect="false" />
            <ClientEvents OnGridCreated="OnGridCreated" />
        </ClientSettings>
        <GroupingSettings ShowUnGroupButton="true" CaseSensitive="false" />
        <MasterTableView Width="100%" CommandItemDisplay="Top" GroupLoadMode="Client" ShowGroupFooter="true">
            <CommandItemTemplate>
                <div>
                    <table border="0" cellpadding="0" cellspacing="0" width="100%">
                        <tr>
                            <td colspan="2" valign="top" align="center" style="color: White; font-weight: bold;
                                font-size: 16px;">
                                <%# radComboReport.Text %>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2" valign="top" style="color: White;">
                                <table border="0" cellpadding="0" cellspacing="0" width="1000px">
                                    <tr>
                                        <td valign="top" style="color: White; width: 800px;">
                                            <b>Source: </b>
                                            <%# radComboSource.Text %>
                                        </td>
                                        <td valign="top" style="color: White;">
                                            <b>Run By:</b>
                                            <%# GetUserName() %>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td valign="top" style="color: White; width: 800px;">
                                            <b>Recon: </b>
                                            <%# radRecons.Text %>
                                        </td>
                                        <td valign="top" style="color: White;">
                                            <b>Run Date:</b>
                                            <%# System.DateTime.Now.ToShortDateString() %>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td valign="top" style="color: White;">
                                <asp:CheckBox ID="chkShowHideFilters" runat="server" CssClass="tdText" Checked="false"
                                    onclick="showHideFilterItem(this.checked);" />
                                <b>Show Filter</b>
                            </td>
                            <td align="right" valign="top" style="color: White;">
                                <b>Export</b
                                <asp:LinkButton ID="btnExportToExcel" runat="server" CommandName="ExportToExcel">
                                                    <img src="Images/Icons/excel.png" alt="Export to Excel" style="border: 0px; vertical-align: middle;" />
                                                       
                                </asp:LinkButton>
                                  
                                <asp:LinkButton ID="btnExportToWord" runat="server" CommandName="ExportToWord">
                                                    <img src="Images/Icons/word.png" alt="Export to Word" style="border: 0px; vertical-align: middle;" />
                                                       
                                </asp:LinkButton>
                                  
                                <asp:LinkButton ID="btnExportToPDF" runat="server" CommandName="ExportToPdf">
                                                    <img src="Images/Icons/pdf.png" alt="Export to PDF" style="border: 0px; vertical-align: middle;" />
                                                       
                                </asp:LinkButton>
                            </td>
                        </tr>
                    </table>
                </div>
            </CommandItemTemplate>
            <HeaderStyle Font-Bold="true" />
            <Columns />
        </MasterTableView>
    </telerik:RadGrid>

3 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 04 Jun 2012, 04:54 PM
Hello Vatsal,

Please check below code snippet.
protected void RadGrid1_PdfExporting(object sender, GridPdfExportingArgs e)
       {
           string customHTML = "<div width=\"100%\" style=\"text-align:center;font-size:12px;font-family:Verdana;\">SET YOUR HEADER HERE</div>";
           e.RawHTML = customHTML + e.RawHTML;
 
       }


Thanks,
Jayesh Goyani
0
Vatsal
Top achievements
Rank 2
answered on 05 Jun 2012, 12:22 PM
It's not working :(. I try below code. ( Please also see commented line ). Now I am curious why this not working? Is it problem in telerik grid or in my coding? Div is working but table is not working!!!

protected void radGridReportData_PdfExporting(object source, GridPdfExportingArgs e)
       {
           //string customHTML = \"<div width=\\"100%\\" style=\\"text-align:center;font-size:12px;font-family:Verdana;\\">SET YOUR HEADER HERE</div>\";
           //string customHTML = "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"><tr><td colspan=\"2\" valign=\"top\" align=\"center\" style=\"color: White; font-weight: bold;font-size: 16px;\">" + radComboReport.Text + "</td></tr><tr><td colspan=\"2\" valign=\"top\" style=\"color: White;\"><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"1000px\"><tr><td valign=\"top\" style=\"color: White; width: 800px;\"><b>Source: </b>" + radComboSource.Text + "</td><td valign=\"top\" style=\"color: White;\"><b>Run By:</b>" + STP.Web.PageUtils.GetUserName() + "</td></tr><tr><td valign=\"top\" style=\"color: White; width: 800px;\"><b>Recon: </b>" + radRecons.Text + "</td><td valign=\"top\" style=\"color: White;\"><b>Run Date:</b>" + System.DateTime.Now.ToShortDateString() + "</td></tr></table></td></tr>";
           string customHTML = "<table><tr><td>TEST</td></tr></table>";
           e.RawHTML = customHTML + e.RawHTML;
       }

0
Vatsal
Top achievements
Rank 2
answered on 14 Jun 2012, 01:04 PM
Can anyone from telerik team help me out from this issue? Please...
Tags
Grid
Asked by
Vatsal
Top achievements
Rank 2
Answers by
Jayesh Goyani
Top achievements
Rank 2
Vatsal
Top achievements
Rank 2
Share this question
or