lost footer values when exporting gridview to excel


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.
 
Ad

Advertisements

E

Edward Wood

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top