Yogesh Vedpathak

Yogesh Vedpathak

  • 678
  • 1.4k
  • 190.2k

Export All Data (Paging in a Gridview ) To Excel sheet

Apr 4 2018 4:20 AM
Hello I want to Export All Data (Paging in a Gridview ) To Excel sheet
 
Current Status: Export Data Working But getting only 1 Page data when i am into that page
 
I want to export data ( Data in all pages ) into excel sheet ..
 
Code here ...
  1. protected void ExportToExcel_click(object sender, EventArgs e)  
  2. {  
  3. ExportGridToExcel();  
  4. }  
  5. protected void ExportGridToExcel()  
  6. {  
  7. Response.Clear();  
  8. Response.Buffer = true;  
  9. Response.ClearContent();  
  10. Response.ClearHeaders();  
  11. Response.Charset = "";  
  12. string FileName = "Yogesh" + DateTime.Now + ".xls";  
  13. StringWriter strwritter = new StringWriter();  
  14. HtmlTextWriter htmltextwrtter = new HtmlTextWriter(strwritter);  
  15. GridView1.AllowPaging = false;  
  16. Response.Cache.SetCacheability(HttpCacheability.NoCache);  
  17. Response.ContentType = "application/vnd.ms-excel";  
  18. Response.AddHeader("Content-Disposition""attachment;filename=" + FileName);  
  19. GridView1.GridLines = GridLines.Both;  
  20. GridView1.HeaderStyle.Font.Bold = true;  
  21. GridView1.RenderControl(htmltextwrtter);  
  22. // GridView1.AllowPaging = false;  
  23. Response.Write(strwritter.ToString());  
  24. Response.Flush();  
  25. Response.End();  
  26. }

Answers (2)