C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » ASP.NET GridView »

Export GridView To Excel/word Using asp.net


Posted Date: 09 Oct 2009    Resource Type: Code Snippets    Category: ASP.NET GridView
Author: priyaraviMember Level: Silver    
Rating: 1 out of 5Points: 10



Export Grid view to Excel/Word:


protected void binddata()
{
con.ConnectionString = "data source=.;initial catalog=priya;integrated security=true";
con.Open();
com.Connection = con;
com.CommandText = "select * from emp";
ada.SelectCommand = com;
ada.Fill(ds, "emp");
GridView1.DataSource = ds;
GridView1.DataBind();
}

In button Click Event:
protected void Export_Click(object sender, EventArgs e)
{
Response.Clear();
Response.Buffer = true;
//For Word:
//Response.AddHeader("content-disposition", "attachment;filename=data.doc");
//Response.ContentType = "application/vnd.ms-word";
//For Excel
Response.AddHeader("content-disposition", "attachment;filename=data.xls");
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
this.EnableViewState = false;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
GridView1.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
}


public override void VerifyRenderingInServerForm(Control control)
{
/* Confirms that an HtmlForm control is rendered for the specified ASP.NET
server control at run time. */
}

			


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 GridView To Excel/word Using asp.net  .  

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: getting value of invisible boundfield in gridview - (vbscript)
Previous Resource: Date Validation in GridView
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET GridView


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use