public override void VerifyRenderingInServerForm(Control control) { }
protected void btnConvertpdf_Click(object sender, EventArgs e)
{
#region pdf
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=BRS.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
gridviewid.AllowPaging = false;
gridviewid.DataBind();
gridviewid.RenderControl(hw);
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();
#endregion
}
protected void btnConvertexcel_Click(object sender, EventArgs e)
{
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "BRS.xls"));
Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
gridviewid.AllowPaging = false; gridviewid.DataBind();
gridviewid.HeaderRow.Style.Add("background-color", "#FFFFFF");
gridviewid.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
Note: itextshrp.dll shoul be used and page event validation should be false
using iTextSharp.text;
using iTextSharp.text.html.simpleparser;
using iTextSharp.text.pdf;
using System.Web.UI.WebControls;
(EnableEventValidation = "false" )
protected void btnConvertpdf_Click(object sender, EventArgs e)
{
#region pdf
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=BRS.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
gridviewid.AllowPaging = false;
gridviewid.DataBind();
gridviewid.RenderControl(hw);
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();
#endregion
}
protected void btnConvertexcel_Click(object sender, EventArgs e)
{
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "BRS.xls"));
Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
gridviewid.AllowPaging = false; gridviewid.DataBind();
gridviewid.HeaderRow.Style.Add("background-color", "#FFFFFF");
gridviewid.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
Note: itextshrp.dll shoul be used and page event validation should be false
using iTextSharp.text;
using iTextSharp.text.html.simpleparser;
using iTextSharp.text.pdf;
using System.Web.UI.WebControls;
(EnableEventValidation = "false" )