Hi All, I developing a module where i need to export my gridview to execl or pdf. when i ever i click on the button to export to execl, i got the error dialog box show below.
its takes all the content of the page including the header and the menu into the execl file and also show image below in the execl. though the content of the Gridview is display in the execl with all the controls of the page.
below is my code on my button click to export the GridView to execl
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "WeeklyReport.xls"));
Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
GridView1.AllowPaging = false;
BindGrid();
//Change the Header Row back to white color
GridView1.HeaderRow.Style.Add("background-color", "#FFFFFF");
//Applying stlye to gridview header cells
for (int i = 0; i < GridView1.HeaderRow.Cells.Count; i++)
{
GridView1.HeaderRow.Cells[i].Style.Add("background-color", "#df5015");
}
GridView1.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();