Pages

Subscribe:

Ads 468x60px

Thursday, March 15, 2012

how to Export Grid View Data into Excel in asp.net using c#

In this web programming tutorial we will learn that how we can export grid view's Data into an excel sheet in asp.net using c#.

protected void BtnExport_Click1(object sender, ImageClickEventArgs e)
{
string attachment = "attachment; filename=Contacts.xls";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
GridView1.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}

No comments:

Post a Comment