Reputation: 33
when i add the below code working fine but it only export data from Gridview in one page not all data if it enable paging ,
please give me your advise :)
protected void BtnExport_Click(object sender, EventArgs e)
{
Response.ClearContent();
Response.AppendHeader("content-disposition", "attachment; filename=Off-Board.xls");
Response.ContentType = "application/excel";
StringWriter stringWriter = new StringWriter();
HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);
GridView_Report.RenderControl(htmlTextWriter);
Response.Write(stringWriter.ToString());
Response.End();
}
enter code here
Upvotes: 0
Views: 75
Reputation:
After Export
GridView_Report.AlloPaging=True;
GrridView_Report.DataSource=Your_datasource;
GridView_Report.DataBind();
Upvotes: 2
Reputation: 4630
try including
GridView_Report.AllowPaging=False;
GridView_Report.DataSource=your_datasource;
GridView_Report.DataBind();
and after export, set
GridView_Report.AllowPaging=True;
GridView_Report.DataSource=your_datasource;
GridView_Report.DataBind();
in your case
protected void BtnExport_Click(object sender, EventArgs e)
{
Response.ClearContent();
Response.AppendHeader("content-disposition", "attachment; filename=Off-Board.xls");
Response.ContentType = "application/excel";
//here
GridView_Report.AllowPaging=False;
GridView_Report.DataSource=your_datasource;
GridView_Report.DataBind();
StringWriter stringWriter = new StringWriter();
HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);
GridView_Report.RenderControl(htmlTextWriter);
Response.Write(stringWriter.ToString());
Response.End();
GridView_Report.AllowPaging=True;
GridView_Report.DataSource=your_datasource;
GridView_Report.DataBind();
}
Upvotes: 1