Following is the function in c# which will export passed gridview to csv file. Note that this function not work if gridview have Autogeneratedcolumn property to true, to make it dynamic you have to add column through code, how to do that see category Gridview posts. public static void ExportToCsv( string fileName, GridView gv, string Title) { HttpContext .Current.Response.Clear(); HttpContext .Current.Response.AddHeader( "content-disposition" , string.Format( "attachment; filename={0}" , fileName)); HttpContext .Current.Response.ContentType = "application/ms-excel" ; using ( StringWriter objSw = new StringWriter ()) { // Create a table to contain the grid Table table = new Table (); // include the gridline settings table.GridLines = gv.GridLines; objSw.Write( "Report: " + Title +
Nodejs MongoDB .Net core C# LINQ Entity Framework MVC Programming Tips & Tricks and lot more