I have a list and would like to export to Excel, this code is bringing the records correctly, it just does not export the file.
Do I need to add something else or would I have another way?
CorpDAO dao = new CorpDAO();
List<CorpCRM> listaExport = dao.ListarCorp(produto, anomes, nome, matricula, pernumber);
var listCarregaExcel = listaExport;
DataGrid rptExcel = new DataGrid();
rptExcel.DataSource = listCarregaExcel;
rptExcel.DataBind();
Response.Clear();
Response.Buffer = true;
Response.ContentEncoding = System.Text.Encoding.GetEncoding("ISO-8859-1");
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("content-disposition", "attachment;filename=Relatório_lista.xls");
Response.Charset = "";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
rptExcel.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
rptExcel = null;
listCarregaExcel = null;
Response.End();