first row blank when export from gridview to excel with master pages included project
-
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
-
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
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