private void ExportMaterials() { GridMaterials.AllowPaging = false; GridMaterials.DataBind(); Response.Clear(); Response.Buffer = true; Response.ClearContent(); Response.ClearHeaders(); Response.Charset = ""; string FileName = "MaterialsData " + 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); GridMaterials.GridLines = GridLines.Both; GridMaterials.HeaderStyle.Font.Bold = true; GridMaterials.RenderControl(htmltextwrtter); Response.Write(strwritter.ToString()); Response.End(); GridMaterials.AllowPaging = true; GridMaterials.DataBind(); }
protected void btnExportMaterialPDF_Click(object sender, ImageClickEventArgs e) { GridMaterials.AllowPaging = false; GridMaterials.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=InternalOrdersMaterial - " + DateTime.Now.ToShortDateString() + ".pdf"); GridMaterials.GridLines = GridLines.Horizontal; GridMaterials.HeaderStyle.Font.Bold = true; GridMaterials.HeaderStyle.ForeColor = System.Drawing.Color.DarkBlue; GridMaterials.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(); GridMaterials.AllowPaging = true; GridMaterials.DataBind(); }
protected void btnGetMaterialData_Click(object sender, EventArgs e) { GridMaterials.DataBind(); Page.ClientScript.RegisterStartupScript(this.GetType(), "EnterText", "SelectMaterial();", true); }