I am generating pdf reports from the following code.But when I open the pdf files it gives me error.Tell me where I am going wrong.PDF files is generated successfully.Also If I generate reports in excel form it runs fine.
public override void VerifyRenderingInServerForm(Control control)
{
/* Confirms that an HtmlForm control is rendered for the specified ASP.NET
server control at run time. */
}
protected void btnPrint_Click(object sender, EventArgs e)
{
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=FileName.pdf");
Response.Charset = "";
// If you want the option to open the Excel file without saving then
// comment out the line below
// Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.pdf";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
Gridview1.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
}
But I have colourful gridview so when I export gridview with word,excel or pdf it comes with colours.So I want exported gridview in simple form.And also My gridview is having page numbers so they are also displayed in exported gridview.Also when if I am
using GridView1.DataBind(); inside the click event of print button then output comes like
<div>
</div>
So when I have deleted GridView1.DataBind(); then output came normally.
anup ganatra
Member
15 Points
26 Posts
Report generated from gridview in pdf form is not working
Feb 29, 2012 09:52 AM|LINK
Hello,
I am generating pdf reports from the following code.But when I open the pdf files it gives me error.Tell me where I am going wrong.PDF files is generated successfully.Also If I generate reports in excel form it runs fine.
public override void VerifyRenderingInServerForm(Control control) { /* Confirms that an HtmlForm control is rendered for the specified ASP.NET server control at run time. */ } protected void btnPrint_Click(object sender, EventArgs e) { Response.Clear(); Response.AddHeader("content-disposition", "attachment;filename=FileName.pdf"); Response.Charset = ""; // If you want the option to open the Excel file without saving then // comment out the line below // Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = "application/vnd.pdf"; System.IO.StringWriter stringWrite = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); Gridview1.RenderControl(htmlWrite); Response.Write(stringWrite.ToString()); Response.End(); }snajp3er
Member
97 Points
26 Posts
Re: Report generated from gridview in pdf form is not working
Feb 29, 2012 12:48 PM|LINK
What error it gives you (error message). Do you use itextsharp to print pdf? Maybe you forgot close filestream after writing pdf file?
Here you can read about printing gridview to pdf http://www.aspsnippets.com/Articles/Export-GridView-To-Word-Excel-PDF-CSV-Formats-in-ASP.Net.aspx.
anup ganatra
Member
15 Points
26 Posts
Re: Report generated from gridview in pdf form is not working
Mar 02, 2012 06:11 AM|LINK
Hi,
But I have colourful gridview so when I export gridview with word,excel or pdf it comes with colours.So I want exported gridview in simple form.And also My gridview is having page numbers so they are also displayed in exported gridview.Also when if I am using GridView1.DataBind(); inside the click event of print button then output comes like
So when I have deleted GridView1.DataBind(); then output came normally.