Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi! all
How can i export specific columns in gridview instead of exporting the whole gridview.
Following is the normal code i've written which works fine, but i want to export some limited number of columns.
Please help me out

Following is my code which works fine:
C#
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=Untitled.xls");
Response.Charset = "";
// If you want the option to open the Excel file without saving then
// comment out the line below
// Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);
worklistGridView.RenderControl(htmlWriter);
Response.Write(stringWriter.ToString());
Response.End();
Posted
Updated 14-Mar-11 3:44am
v2
Comments
Nuri Ismail 14-Mar-11 9:45am    
Fixed code formatting.

 
Share this answer
 
Comments
Albin Abel 18-Mar-11 8:31am    
Google is best friend :)
 
Share this answer
 
Comments
Albin Abel 18-Mar-11 8:31am    
Good link

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