Click here to Skip to main content
16,013,747 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a grid view in a certain page. I need to export the contents of the grid view to MS Excel format.

Please Help.

Thank You.
Posted

Hi Singha Roy,

XML
<pre lang="cs">Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "Customers.xls"));
Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
gvdetails.AllowPaging = false;
gvdetails.DataBind();
gvdetails.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();</pre>
 
Share this answer
 
See this link.The only task i left on you is to choose the one you like.

GridView export to excel in asp.net[^]
 
Share this answer
 
For large datagrid contents, please see this :

Export very large data to Excel file[^]
 
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