Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7037257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:31:22+00:00 2026-05-28T01:31:22+00:00

I have a Grid in an ASP.NET page and I have an Export button.

  • 0

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?

Thanks

    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(" ", " ") + "\",";
                   lCommand.CommandText += "\"" + lItem.Cells[_gSource].Text.Replace(" ", " ") + "\",";
                   lCommand.CommandText += "\"" + lItem.Cells[_gAccountName].Text.Replace(" ", " ") + "\",";
                   lCommand.CommandText += "\"" + lItem.Cells[_gCreatedOn].Text.Replace(" ", " ") + "\",";
                   lCommand.CommandText += "\"" + lItem.Cells[_gContactFullName].Text.Replace(" ", " ") + "\",";
                   lCommand.CommandText += "\"" + lItem.Cells[_gPriority].Text.Replace(" ", " ") + "\",";
                   lCommand.CommandText += "\"" + lItem.Cells[_gStreet1].Text.Replace(" ", " ") + "\",";
                   lCommand.CommandText += "\"" + lItem.Cells[_gStreet2].Text.Replace(" ", " ") + "\",";
                   lCommand.CommandText += "\"" + lItem.Cells[_gZIP].Text.Replace(" ", " ") + "\",";
                   lCommand.CommandText += "\"" + lItem.Cells[_gCity].Text.Replace(" ", " ") + "\",";
                   lCommand.CommandText += "\"" + lItem.Cells[_gState].Text.Replace(" ", " ") + "\",";
                   lCommand.CommandText += ")";
                   lCommand.ExecuteNonQuery();
                 }
              }

             lConnection.Close();
          }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T01:31:22+00:00Added an answer on May 28, 2026 at 1:31 am

    Is the grid being used to edit or manipulate the data in any way? Generally it would be better to export the values from the data from which the grid is populated, not from the grid itself.

    After all, if the grid has paging, then the actual grid being displayed contains only the single page of data. But the data source from which it is populated contains everything.

    Export from the data source, not from the UI controls.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an asp.net-mvc site. I have a page with a grid of data
I have an asp.net page where two grid views are available showing current stock
I currently have a single asp.net page that displays a grid with a single
I have a ASP.Net web page with a grid view. I want to filter
I have an Asp.Net page containing one grid and an image. The image is
I have 12 buttons in ASP.NET page. I want to color the button; But
In a Asp.net page I have a grid of departments that is displayed with
In my ASP.NET page, I have a generic class that is defined as below:
I have a DDL and a ASP .net Grid view in my aspx page.
In one my ASP.NET web page, I have used a Grid and embedded a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.