<table> <tr> <asp:ImageButton ID="ImageButtonPDF" runat="server" AlternateText="View" ToolTip="Click to view PDF report" ImageUrl="~/Graphics/Buttons/printpreview.gif" OnClick="ImageButtonPDF_Click" /> </tr> <tr> <td> <asp:GridView ID="Gridview1" BorderStyle="None" runat="server" AutoGenerateColumns="true" OnRowDataBound="gvRedemptionFunding_RowDataBound" ShowFooter="true" Gridlines="none"> <EmptyDataTemplate> <%= sbEmptyGridTemplate %> </EmptyDataTemplate> <HeaderStyle CssClass="reportHeaderTitle" HorizontalAlign="right" /> <RowStyle CssClass="reportGridItem" HorizontalAlign="right" /> <FooterStyle CssClass="reportGridItem" HorizontalAlign="right" Height="30px" Font-Bold="true" /> </asp:GridView> </td> </tr> </table>
Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "attachment;filename=Export.pdf"); Response.Cache.SetCacheability(HttpCacheability.NoCache); StringWriter sw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); HtmlForm frm = new HtmlForm(); Gridview1.Parent.Controls.Add(frm); frm.Attributes["runat"] = "server"; frm.Controls.Add(Gridview1); frm.RenderControl(hw); StringReader sr = new StringReader(sw.ToString()); Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f); HTMLWorker htmlparser = new HTMLWorker(pdfDoc); PdfWriter.GetInstance(pdfDoc, Response.OutputStream); pdfDoc.Open(); htmlparser.Parse(sr); pdfDoc.Close(); Response.Write(pdfDoc); Response.End();
Gridview1.RenderControl(hw);
HtmlForm frm = new HtmlForm(); Gridview1.Parent.Controls.Add(frm); frm.Attributes["runat"] = "server"; frm.Controls.Add(Gridview1); frm.RenderControl(hw);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)