"add an “export to excel” button to a webpage to export gridview to excel in webapplication" Code Answer

1

try below code on the button click

// get datatable that datagrid is bound to.
var datatable = (datatable)datagrid.datasource;

// create new excelfile.
var ef = new excelfile();
// add new worksheet to the file.
var ws = ef.worksheets.add(datatable.tablename);
// insert the data from datatable to the worksheet starting at cell "a1".
ws.insertdatatable(datatable, "a1", true);

// stream file to browser.
response.clear();
response.contenttype = "application/vnd.ms-excel";
response.addheader("content-disposition", "attachment; filename=employee.xls");
ef.savexls(response.outputstream);
response.end();
By imladris on April 4 2022

Answers related to “add an “export to excel” button to a webpage to export gridview to excel in webapplication”

Only authorized users can answer the Search term. Please sign in first, or register a free account.