lost footer values when exporting gridview to excel

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello Everyone,

I have a gridview. I calculated some values in the gridview for the footer
of the gridview so basically I am adding all the values that are displayed in
the gridview for each column and displaying the total in the footer of the
gridview.
Now I export the gridview to excel spreadsheet with the code below.
Everything is exported well except the footer value become zero in the excel
spreadsheet. Can anyone tell me how can i fix this problem.
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);
HtmlForm frm = new HtmlForm();
dgAgentActivity.Parent.Controls.Add(frm);
frm.Attributes["runat"] = "server";
frm.Controls.Add(dgAgentActivity);
frm.RenderControl(htw);
Any help will be greatly apprecaited.

Thanks.
 
Old old topic but I recently encountered the same problem and was able to resolve it.

Simply Bind your GridView/Datagrid prior to rendering it for response.

Example

StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
MyGridView.DataBind();
MyGridView.RenderControl(htw);
Response.Write(style);
Response.Write(sw.ToString());
Response.End();
Hello Everyone,

I have a gridview. I calculated some values in the gridview for the footer
of the gridview so basically I am adding all the values that are displayed in
the gridview for each column and displaying the total in the footer of the
gridview.
Now I export the gridview to excel spreadsheet with the code below.
Everything is exported well except the footer value become zero in the excel
spreadsheet. Can anyone tell me how can i fix this problem.
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);
HtmlForm frm = new HtmlForm();
dgAgentActivity.Parent.Controls.Add(frm);
frm.Attributes["runat"] = "server";
frm.Controls.Add(dgAgentActivity);
frm.RenderControl(htw);
Any help will be greatly apprecaited.

Thanks.

Submitted via EggHeadCafe
ASP.NET In-Memory Image Control with Built-In Resizing of Posted File
http://www.eggheadcafe.com/tutorial...rol-with-builtin-resizing-of-posted-file.aspx
 
Back
Top