I want to export ASPxGridView while clicking on a button as export.
I am using code below but not getting the needed results:
protected void btn_excel_Click1(object sender, EventArgs e)
{
ASPxGridViewExporter1 . WriteXlsToResponse();
}
Try this
Session["Excel"] - The items that you want to export (In my case I'm storing this in a session).
using (var exporter = new NpoiExport()) {
DataTable dt = new DataTable();
dt = (DataTable)Session["Excel"];
exporter.ExportDataTableToWorkbook(dt, "Result");
string saveAsFileName = string.Format("Results-{0:d}.xls", DateTime.Now);
Response.ContentType = "application/excel";
Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", saveAsFileName));
Response.Clear();
Response.BinaryWrite(exporter.GetBytes());
Response.End();
}