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 !




Datagrid to Excel


Posted Date: 20 Jun 2008    Resource Type: Code Snippets    Category: C# Syntax

Posted By: vivek       Member Level: Bronze
Rating:     Points: 5



The following code ssample transfers the contents of a DataGrid control in .NET to an Excel file. This process is carried out over a Button click event. Before running the code we have to change the button's property : EnableEventValidation="false"



public override void VerifyRenderingInServerForm(Control control)
{

}

protected void btnExcel_Click(object sender, EventArgs e)
{
grvAcceptanceStatus.Columns[0].Visible = false;
grvAcceptanceStatus.Columns[1].Visible = false;

Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");

Response.Charset = "";

// 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);

grvAcceptanceStatus.RenderControl(htmlWrite);

Response.Write(stringWrite.ToString());

Response.End();

}




Responses


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

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Transfer Datagrid contents to xls file  .  Transfer Datagrid contents to Excel file  .  Transfer Datagrid contents to Excel  .  Transfer Datagrid contents  .  

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: Use of Switch Case Statements
Previous Resource: How to access sealed class methods
Return to Discussion Resource Index
Post New Resource
Category: C# Syntax


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

web conferencing

Contact Us    Privacy Policy    Terms Of Use