Monday, November 3, 2014

DataGrid Export to Excel

//btnExporttoExcel
Response.Clear();
Response.Buffer = true;
Response.ClearContent();
Response.ClearHeaders();
Response.Charset = "";
string FileName = "MS EXCEL" + DateTime.Now + ".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);
dgpayment.GridLines = GridLines.Both;
dgpayment.HeaderStyle.Font.Bold = true;
dgpayment.RenderControl(htmltextwrtter);
Response.Write(strwritter.ToString());
Response.End();

//another method

public override void VerifyRenderingInServerForm(Control control)
        {
            //
        }

No comments:

Post a Comment