lost footer values when exporting gridview to excel

Discussion in 'ASP .Net' started by =?Utf-8?B?Vmlua2k=?=, Jul 24, 2007.

  1. 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.
     
    =?Utf-8?B?Vmlua2k=?=, Jul 24, 2007
    #1
    1. Advertising

  2. =?Utf-8?B?Vmlua2k=?=

    Edward Wood Guest

    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();

    > On Tuesday, July 24, 2007 2:58 PM Vink wrote:


    > 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
     
    Edward Wood, Jan 31, 2011
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Luis Esteban Valencia
    Replies:
    1
    Views:
    1,404
    Carl Prothman [MVP]
    Jan 12, 2005
  2. =?Utf-8?B?TmFuY3lB?=

    Problem exporting datagrid with numeric values to Excel

    =?Utf-8?B?TmFuY3lB?=, Apr 15, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    1,633
    Elton Wang
    Apr 16, 2005
  3. Mike P

    exporting gridview to excel

    Mike P, Jun 8, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    626
    Mike P
    Jun 8, 2006
  4. Replies:
    3
    Views:
    7,752
    reena_pgdi
    May 21, 2010
  5. Doogie
    Replies:
    1
    Views:
    461
    sloan
    Nov 19, 2008
Loading...

Share This Page