C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Training   ASP.NET Web Hosting    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

Play Silverlight Games or Submit your Silverlight applications and earn 90% AdSense revenue.

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Resources » Code Snippets » DataGridView »

Export to Excel from Grid View


Posted Date: 09 Oct 2008    Resource Type: Code Snippets    Category: DataGridView
Author: Ashutosh KumarMember Level: Gold    
Rating: Points: 10



This code descibes how to export data from gridview to excel sheet.

Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=SalesPersonreport.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 stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

GridView gvExport = new GridView();// grid a grid typr instance for exporting grid data to excel
if (dsReport.Tables[0].Rows.Count > 0)
{
gvExport.DataSource = dsReport;//objbus.ExporttoExcel(querryvalue);
gvExport.DataBind();
}

gvExport.RenderControl(htmlWrite); // rendering grid data to html writter
Response.Write(stringWrite.ToString()); //this will prompt Download message




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Export to Excel in Grid View  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Displaying Images in GridView
Previous Resource: Add boundfield column in gridview at runtime
Return to Discussion Resource Index
Post New Resource
Category: DataGridView


Post resources and earn money!
 
Related Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use