C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

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




Export to Excel from Grid View


Posted Date: 09 Oct 2008    Resource Type: Code Snippets    Category: DataGridView

Posted By: Ashutosh Kumar       Member 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  
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   BizTalk Adaptors    Web Design

fax server

Contact Us    Privacy Policy    Terms Of Use