SQL SERVER Performance – JSON vs XML
3 days ago
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();
}
Post a Comment