asp.netpaginationexport-to-excel

How to remove paging text in excel sheet while exporting data from GridView to Excelsheet?


I implemented export to excel functionality in asp.net application.Here i export data from Grid-view to excel-sheet.I also applied Paging in Grid-view.

So when i export data from Grid-view to excel sheet,paging text also display in excel sheet as shown in the given image.

enter image description here

How can we remove it

i follow the below approach for exporting data

Code-Behind:

Response.Clear()
Response.ClearHeaders()
Response.AddHeader("content-disposition", "attachment;filename=sample.xls")
Response.Charset = ""
Response.ContentType = "application/vnd.xls"

Dim sb As StringBuilder = New StringBuilder()
Dim objStringWriter As StringWriter = New StringWriter(sb)
Dim objHtmlTextWriter As HtmlTextWriter = New HtmlTextWriter(objStringWriter)

//gvSample is Gridview server control
gvSample.RenderControl(objHtmlTextWriter)

Response.ContentEncoding = Encoding.Unicode
Response.BinaryWrite(System.Text.Encoding.Unicode.GetPreamble())
Response.Write(objStringWriter)
Response.End()

Thanks


Solution

  • Before rendering - disable the paging, bind the data and then render:

     gvSample.AllowPaging = false;
     gvSample.DataSource = ds; //Data Source
     gvSample.DataBind();
     gvSample.RenderControl(objHtmlTextWriter)