saya nurul 0 Report post Posted December 26, 2012 salam, mcm ne kalu nk export gridview ke pdf file?sy telh cuba koding spt dibwh ni tp sy dpt error bila run. mcm ne nk solve mslh ni? harap ada yg boleh membntu..Trima kasih :) protected void btnExportPDF_Click(object sender, EventArgs e) { Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "attachment;filename=UserDetails.pdf"); Response.Cache.SetCacheability(HttpCacheability.NoCache); StringWriter sw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); //DataList1.AllowPaging = false; DataList1.DataBind(); DataList1.RenderControl(hw); //DataList1.HeaderRow.Style.Add("width", "15%"); //DataList1.HeaderRow.Style.Add("font-size", "10px"); DataList1.Style.Add("text-decoration", "none"); DataList1.Style.Add("font-family", "Arial, Helvetica, sans-serif;"); DataList1.Style.Add("font-size", "8px"); StringReader sr = new StringReader(sw.ToString()); Document pdfDoc = new Document(PageSize.A2, 7f, 7f, 7f, 0f); HTMLWorker htmlparser = new HTMLWorker(pdfDoc); PdfWriter.GetInstance(pdfDoc, Response.OutputStream); pdfDoc.Open(); htmlparser.Parse(sr); pdfDoc.Close(); Response.Write(pdfDoc); Response.End(); } error yg keluar : The document has no pages. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details: System.IO.IOException: The document has no pages.Source Error: Line 208: pdfDoc.Open(); Line 209: htmlparser.Parse(sr); Line 210: pdfDoc.Close(); Line 211: Response.Write(pdfDoc); Line 212: Response.End(); Quote Share this post Link to post Share on other sites
Chuki2 32 Report post Posted December 26, 2012 Salam... selamat datang ke putera.com sekali lagi...:) Untuk papar code didalam forum, digalakkan mengunakan tag '[ C O D E ] [ / C O D E ]' untuk memudahkan kami membaca code anda....;) Kembali semula pada masalah anda boleh try tengok disini http://www.aspdotnet-suresh.com/2011/04/how-to-export-gridview-data-to-pdf.html Happy programming.....:D Quote Share this post Link to post Share on other sites
saya nurul 0 Report post Posted December 27, 2012 hehe...maaf,sbb sy bru taw..sy nk tgk kode kt link yg di atas 2,tp still dpt error yg sma je.. Quote Share this post Link to post Share on other sites