protected void btnExportCustomerOrdersPDF_Click(object sender, ImageClickEventArgs e) { GridOrders.AllowPaging = false; GridOrders.DataBind(); Response.Clear(); Response.Buffer = true; Response.ClearContent(); Response.ClearHeaders(); Response.Charset = ""; StringWriter sw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "attachment;filename=InternalOrdersOfCustomer-" + SelectCustomerOrders.SelectedItem.ToString() + " - " + DateTime.Now.ToShortDateString() + ".pdf"); GridOrders.GridLines = GridLines.Horizontal; GridOrders.HeaderStyle.Font.Bold = true; GridOrders.HeaderStyle.ForeColor = System.Drawing.Color.DarkBlue; GridOrders.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(); GridOrders.AllowPaging = true; GridOrders.DataBind(); }
protected void btnExportCustomerOrdersExcel_Click(object sender, ImageClickEventArgs e) { GridOrders.AllowPaging = false; GridOrders.DataBind(); Response.Clear(); Response.Buffer = true; Response.ClearContent(); Response.ClearHeaders(); Response.Charset = ""; string FileName = "InternalOrders - Customer - " + SelectCustomerOrders.SelectedItem.ToString() + " - " + DateTime.Now.ToShortDateString() + ".xls"; StringWriter strwritter = new StringWriter(); HtmlTextWriter htmltextwrtter = new HtmlTextWriter(strwritter); Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = "application/vnd.ms-excel"; Response.AddHeader("Content-Disposition", "attachment;filename=" + FileName); GridOrders.GridLines = GridLines.Both; GridOrders.HeaderStyle.Font.Bold = true; GridOrders.RenderControl(htmltextwrtter); Response.Write(strwritter.ToString()); Response.End(); GridOrders.AllowPaging = true; GridOrders.DataBind(); }