title: Listview Control with datapager: How to export to excel and get all data
body: <p>I am having an issue with getting all of the data to export from a Listview control with datapager to excel.  This is my code:</p>
  
  <pre><code>    private void ExportListView()
      {
  
          Response.ClearContent();
          Response.ClearHeaders();
          Response.AddHeader("content-disposition", "attachment;filename=sample.xls");
          Response.Charset = "";
          Response.ContentType = "application/vnd.xls";
  
          StringBuilder sb = new StringBuilder();
          StringWriter objStringWriter = new StringWriter(sb);
          HtmlTextWriter objHtmlTextWriter = new HtmlTextWriter(objStringWriter);
  
          //gvSample is Gridview server control
          HtmlForm frm = new HtmlForm();
          ListView1.Parent.Controls.Add(frm);
          frm.Attributes["runat"] = "server";
          frm.Controls.Add(ListView1);
  
          DataPager pager = (DataPager)ListView1.FindControl("DataPager1");
          pager.PageSize = 1000000;
          frm.RenderControl(objHtmlTextWriter);
  
          Response.ContentEncoding = Encoding.Unicode;
          Response.BinaryWrite(System.Text.Encoding.Unicode.GetPreamble());
          Response.Write(objStringWriter);
          Response.End();
  
  
          //string attachment = "attachment; filename=Data.xls";
          //Response.ClearContent();
          //Response.AddHeader("content-disposition", attachment);
          //Response.ContentType = "application/ms-excel";
          //StringWriter sw = new StringWriter();
          //HtmlTextWriter htw = new HtmlTextWriter(sw);
  
  
  
          //// Create a form to contain the grid
  
  
          //HtmlForm frm = new HtmlForm();
          //ListView1.Parent.Controls.Add(frm);
          //frm.Attributes["runat"] = "server";
          //frm.Controls.Add(ListView1);
  
  
          //frm.RenderControl(htw);
          //Response.Write(sw.ToString());
          //Response.End();
      }
  </code></pre>
  
  <p>Anyone with information on how to do would be great.  The pagination is what is making this impossible.  I need to somehow tell the datapager to disable or max out with all data.  I am just stuck.  There are a million examples out there for Gridview but nothing for ListView and I am wondering if anyone has the answer to this.  Please HELP!!  Thanks!!</p>