Export All Data Not just Displayed Data
<p>I have a Grid in an ASP.NET page and I have an Export button. When the Export button is clicked it executes the method below and fills the Excel document with the data from the Grid. But it only fills it with data that is on Page 1. If I have 100 items and 10 pages it just does page one. I would think it would do all and not just the ones displayed. Any idea why it would do this?</p>

<p>Thanks</p>

<pre><code>    private void fillDocument()
      {
        string lFilename = Leads.xls";
        string lDistributorFolder = Server.MapPath(".") + "\\Portals\\0\\Distributors\\" + _currentUser.UserID.ToString() + "\\";
        string lTemplateFolder = System.Configuration.ConfigurationManager.AppSettings["Templates"];
        System.IO.Directory.CreateDirectory(lDistributorFolder);

        File.Copy(lTemplateFolder + lFilename, lDistributorFolder + lFilename, true);
        string lConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + lDistributorFolder + "\\" + lFilename + ";Extended Properties=\"Excel 8.0;HDR=YES;\"";
        DbProviderFactory lFactory = DbProviderFactories.GetFactory("System.Data.OleDb");
        int lSequence = 0;

        using (DbConnection lConnection = lFactory.CreateConnection())
        {
            lConnection.ConnectionString = lConnectionString;
            lConnection.Open();

        foreach (GridDataItem lItem in grdLeadList.Items)
          {
            lSequence++;

            using (DbCommand lCommand = lConnection.CreateCommand())
              {
                   lCommand.CommandText = "INSERT INTO [Leads$] ";
                   lCommand.CommandText += "(F1,F2,F3,F4,F5,F6,F7,F8,F9,F10,F11,F12,F13,F14,F15,F16,F17,F18,F19,F20,F21) ";
                   lCommand.CommandText += "VALUES(";
                   lCommand.CommandText += "\"" + lSequence.ToString() + "\",";
                   lCommand.CommandText += "\"" + lItem.Cells[_gLeadNumber].Text.Replace("&amp;nbsp;", " ") + "\",";
                   lCommand.CommandText += "\"" + lItem.Cells[_gSource].Text.Replace("&amp;nbsp;", " ") + "\",";
                   lCommand.CommandText += "\"" + lItem.Cells[_gAccountName].Text.Replace("&amp;nbsp;", " ") + "\",";
                   lCommand.CommandText += "\"" + lItem.Cells[_gCreatedOn].Text.Replace("&amp;nbsp;", " ") + "\",";
                   lCommand.CommandText += "\"" + lItem.Cells[_gContactFullName].Text.Replace("&amp;nbsp;", " ") + "\",";
                   lCommand.CommandText += "\"" + lItem.Cells[_gPriority].Text.Replace("&amp;nbsp;", " ") + "\",";
                   lCommand.CommandText += "\"" + lItem.Cells[_gStreet1].Text.Replace("&amp;nbsp;", " ") + "\",";
                   lCommand.CommandText += "\"" + lItem.Cells[_gStreet2].Text.Replace("&amp;nbsp;", " ") + "\",";
                   lCommand.CommandText += "\"" + lItem.Cells[_gZIP].Text.Replace("&amp;nbsp;", " ") + "\",";
                   lCommand.CommandText += "\"" + lItem.Cells[_gCity].Text.Replace("&amp;nbsp;", " ") + "\",";
                   lCommand.CommandText += "\"" + lItem.Cells[_gState].Text.Replace("&amp;nbsp;", " ") + "\",";
                   lCommand.CommandText += ")";
                   lCommand.ExecuteNonQuery();
                 }
              }

             lConnection.Close();
          }
}
</code></pre>
