You need to use Server Side Code.
The easiest option is to convert the back end DataTable
to comma-seperated
file. Then then use Response.Write
to save it as a csv
file. This file can be opened using Excel.
response.ClearContent();
response.Clear();
response.ContentType = "text/plain";
response.AddHeader("Content-Disposition", "attachment; filename=DownloadedData.txt;");
StringBuilder sb = new StringBuilder();
string[] columnNames = dt.Columns.Cast<DataColumn>().
Select(column => column.ColumnName).
ToArray();
sb.AppendLine(string.Join(",", columnNames));
foreach (DataRow row in dt.Rows)
{
string[] fields = row.ItemArray.Select(field => field.ToString()).
ToArray();
sb.AppendLine(string.Join(",", fields));
}
// the most easy way as you have type it
response.Write(sb.ToString());
response.Flush();
response.End();
https://stackoverflow.com/questions/16582993/how-to-save-a-datatable-as-a-csv-file-on-client-pc-asp-net