Click here to Skip to main content
15,999,861 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have the below code which is working fine for exporting the data into excel, but
along with specific html data, its displaying the entire page too in excel sheet:

protected void lnkbtnExport_Click(object sender, EventArgs e)
   {
       ExcelHead.Visible = true;
       string fileName = "attachment;filename= UserProdReport_" + DateTime.Now.ToString("dd-MM-yyyy-hh-mm-ss") + ".xls";
       Response.Clear();
       Response.AddHeader("content-disposition", fileName);
       Response.Charset = "";
       Response.Cache.SetCacheability(HttpCacheability.NoCache);
       Response.ContentType = "application/excel";
       System.IO.StringWriter stringWrite = new System.IO.StringWriter();
       System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
       ExcelHead.RenderControl(htmlWrite);
       gvUserProd.RenderControl(htmlWrite);
       Response.Write(stringWrite);
       Response.End();
       ExcelHead.Visible = false;
   }


Here, it has to display only the 'ExcelHead' and 'gvUserProd'.. but I am getting the entire page content along with these two..

Any idea regarding this issue? Please help me on this.

Regards,
Posted
Updated 9-Mar-11 22:44pm
v4
Comments
Raj.rcr 10-Mar-11 4:46am    
Hi everyone... Thanks for ur no response. Anyways, I got the solution for this issue.. cya

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900