Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. first row blank when export from gridview to excel with master pages included project

first row blank when export from gridview to excel with master pages included project

Scheduled Pinned Locked Moved C#
csharpasp-netsysadminhelptutorial
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dhyanga
    wrote on last edited by
    #1

    Hi, I am trying to export gridview data to excel. It is working fine except the first row in the excel is blank. The code i used for the excel is shown below:

    HttpContext.Current.Response.Clear(); //clear anything in io buffer
    Response.ClearContent();
    HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=GrpFile.xls");
    HttpContext.Current.Response.Charset = "";
    HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
    StringWriter sw = new StringWriter();
    HtmlTextWriter hw = new HtmlTextWriter(sw);
    HtmlForm frm = new HtmlForm();
    gvCampGrp.Parent.Controls.Add(frm);
    frm.Attributes["runat"] = "server";
    frm.Controls.Add(gvCampGrp);
    frm.RenderControl(hw);
    HttpContext.Current.Response.Write(sw.ToString());
    HttpContext.Current.Response.End();

    I also included the following code.

    public override void VerifyRenderingInServerForm(Control control)
    {
    /* Confirms that an HtmlForm control is rendered for the specified ASP.NET
    server control at run time. */
    return;
    }

    How to export data to excel without making its first row empty? Please help.

    Dhyanga

    D 1 Reply Last reply
    0
    • D Dhyanga

      Hi, I am trying to export gridview data to excel. It is working fine except the first row in the excel is blank. The code i used for the excel is shown below:

      HttpContext.Current.Response.Clear(); //clear anything in io buffer
      Response.ClearContent();
      HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=GrpFile.xls");
      HttpContext.Current.Response.Charset = "";
      HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
      StringWriter sw = new StringWriter();
      HtmlTextWriter hw = new HtmlTextWriter(sw);
      HtmlForm frm = new HtmlForm();
      gvCampGrp.Parent.Controls.Add(frm);
      frm.Attributes["runat"] = "server";
      frm.Controls.Add(gvCampGrp);
      frm.RenderControl(hw);
      HttpContext.Current.Response.Write(sw.ToString());
      HttpContext.Current.Response.End();

      I also included the following code.

      public override void VerifyRenderingInServerForm(Control control)
      {
      /* Confirms that an HtmlForm control is rendered for the specified ASP.NET
      server control at run time. */
      return;
      }

      How to export data to excel without making its first row empty? Please help.

      Dhyanga

      D Offline
      D Offline
      Dhyanga
      wrote on last edited by
      #2

      i removed the htmlform code from the section and now it worked fine.

      HttpContext.Current.Response.Clear(); //clear anything in io buffer
      Response.ClearContent();
      HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=GrpFile.xls");
      HttpContext.Current.Response.Charset = "";
      HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
      StringWriter sw = new StringWriter();
      HtmlTextWriter hw = new HtmlTextWriter(sw);
      gvCampGrp.RenderControl(hw);
      HttpContext.Current.Response.Write(sw.ToString());
      HttpContext.Current.Response.End();

      and

      public override void VerifyRenderingInServerForm(Control control)
      {
      /* Confirms that an HtmlForm control is rendered for the specified ASP.NET
      server control at run time. */
      return;
      }

      Dhyanga

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups