private void Convert_Gridto_Excel(string filename) { Response.Clear(); Response.AddHeader("content-disposition", "attachment;filename=" + filename); Response.Charset = ""; // If you want the option to open the Excel file without saving than // comment out the line below // Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = "application/vnd.xls"; System.IO.StringWriter stringWrite = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); Roster_gridvw.RenderControl(htmlWrite); Response.Write(stringWrite.ToString()); Response.End(); }
public void ConvertToExcel(Datagrid myGrid, string Filename) { //other stuff here myGrid.Render(htmlWrite); //do other stuff here } //you call it by CovertToExcel(Roster_gridvw, "myfilename.xls");
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)