DataGrid dgExport = new DataGrid(); dgExport.DataSource = dtExport; dgExport.DataBind(); string Excelfilename = "Test_Excel_Export" + DateTime.Now; Response.Clear(); Response.Buffer = true; Response.ContentType = "application/vnd.ms-excel"; Response.AppendHeader("Content-Disposition:", "attachment; filename=" + Excelfilename + ".xls"); Response.Charset = ""; Response.ContentEncoding = Encoding.Unicode; Response.BinaryWrite(Encoding.Unicode.GetPreamble()); this.EnableViewState = false; System.IO.StringWriter oStringWriter = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter); dgExport.RenderControl(oHtmlTextWriter); Response.Write(oStringWriter.ToString()); Response.End
Response.ContentEncoding = Encoding.Unicode; Response.BinaryWrite(Encoding.Unicode.GetPreamble());
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)