protected void ibtnExportPDFAppTableDoc_Click(object sender, ImageClickEventArgs e) { GridAppTable.AllowPaging = false; GridAppTable.DataSource = grid(); GridAppTable.DataBind(); if (GridAppTable.Rows.Count > 0) { Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "attachment;filename=ApprovedMembership.pdf"); Response.Cache.SetCacheability(HttpCacheability.NoCache); StringWriter sw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); GridAppTable.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(); } }
protected void ibtnExportExcelAppTableDoc_Click(object sender, ImageClickEventArgs e) { GridAppTable.AllowPaging = false; GridAppTable.DataSource = grid(); GridAppTable.DataBind(); if (GridAppTable.Rows.Count > 0) { Response.Clear(); Response.Buffer = true; Response.AddHeader("content-disposition", "attachment;filename=ApprovedMembership.xls"); Response.Charset = ""; Response.ContentType = "application/vnd.ms-excel"; StringWriter sw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); GridAppTable.RenderControl(hw); Response.Output.Write(sw.ToString()); Response.Flush(); Response.End(); } }