0
Posted on 2:06 AM by prajeesh and filed under , ,

Hi friends,

In some situations we need to export grid view content in our asp.net web page to excel sheet for future reference,or printing,here is the sample code to do that.all u have to do is place the following code into click event of export to excel button,and change grid view name and excel filename.

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

}

Shout it kick it on DotNetKicks.com
0
Responses to ... Exporting Grid View into Excel