protected void lbtnDownloadReport_Click(object sender, EventArgs e)
{
GridView gv = new GridView();
gv = Gridview1;
gv.FooterRow.Visible = false;
Download_Excel(gv, "Report.xls");
}
public void Download_Excel(GridView gv, string fileName)
{
HtmlForm form = new HtmlForm();
string attachment = "attachment; filename=" + fileName + ".xls";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/ms-excel";
StringWriter stw = new StringWriter();
HtmlTextWriter htextw = new HtmlTextWriter(stw);
form.Controls.Add(gv);
this.Controls.Add(form);
form.RenderControl(htextw);
Response.Write(stw.ToString());
Response.End();
}