Click here to Skip to main content
15,918,243 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
need button code to export gridview data to ecxel,pls help
Posted

use below code


C#
Response.Clear();
          Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
          Response.Buffer = true;
          Response.ContentType = "application/vnd.xls";
          Response.Charset = "";
          EnableViewState = false;
          System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
          System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
          ClearControls(grd);
          GridView1.RenderControl(oHtmlTextWriter);
          Response.Write(oStringWriter.ToString());
          Response.End();
 
Share this answer
 
v2
 
Share this answer
 
Search Engines are one of the best media to find details around this kind of Questions.

Google Search Result

Bing Search Result
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900