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 4255856
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:16:28+00:00 2026-05-21T05:16:28+00:00

I have a GridView which shows only 50 records at a time through paging.

  • 0

I have a GridView which shows only 50 records at a time through paging. If i bind that to a source say containing 150 records, it works like charm but when the record size increases drastically to 10,00000, it took ages to load data.. So, i want to know is there any way of just loading 50 records at a time which are visible??

I want something like Lazy Loading or the feature of Virtualizing Stack
Panel in wpf.

This is how i am binding to the GridView –

private void LoadCustomers()
        {            
            if (Cache["CustomersData"] == null)
            {
                Business.Customers customers = Business.Customers.GetAllCustomer();
                Cache["CustomersData"] = customers;
            }
            this.customerGridView.DataSource = Cache["CustomersData"];
            this.customerGridView.DataBind();  
        }

And here’s the function which fetch data from DB-

public static Customers GetAllCustomer(int index)
        {
            Customers customers = new Customers();

        NShop_SmallEntities data = new NShop_SmallEntities();
        var dbCustomers = (from c in data.Customers
                            select c).OrderBy(c=> c.CustomerId).Skip(index * 50).Take(50);

        foreach (var dbCustomer in dbCustomers)
        {
            customers.Add(Customer.GetCustomer(dbCustomer));
        }

        return customers;
        }

public static Customer GetCustomer(DAL.Customer dbCustomer)
        {
            return new Customer()
                {
                    CustomerId = dbCustomer.CustomerId,
                    FirstName = dbCustomer.FirstName,
                    LastName = dbCustomer.LastName,
                    Email = dbCustomer.Email,
                    DOB = dbCustomer.DOB,
                    City = dbCustomer.City,
                    State = dbCustomer.State,
                    PostalCode = dbCustomer.PostalCode,
                    Country = dbCustomer.Country,
                    OrderCount = dbCustomer.Orders.Count()
                };
        }
  • 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-21T05:16:29+00:00Added an answer on May 21, 2026 at 5:16 am

    Here is, accoring to your change, how I would do that :

    public static Customers GetAllCustomer(int startIndex, int nbrOfResults, out total) {
       Customers customers = new Customers();
    
       NShop_SmallEntities data = new NShop_SmallEntities();
       var dbCustomers = from c in data.Customers
                         select c;
    
       // Retreiving total number of customers. NEEDED to get 
       // ObjectDataSource working.
       total = dbCustomers.Count();
    
       foreach (var dbCustomer in dbCustomers
                             .Skip((startIndex * nbrOfResults) + 1)
                             .Take(NumberOfResults).ToList() {
          customers.Add(Customer.GetCustomer(dbCustomer));
       }
       return customers;
    }
    
    /// <summary>
    /// This methods must have the same signature than the "real" one... exept the name :oP
    /// </summary>
    public static int GetAllCustomerCount(int startIndex, int nbrOfResults, out total) {
          return (from c in data.Customers select c).Count();
    }
    

    And now in your page ;

    <asp:GridView ID="gvBulletins" runat="server" AllowPaging="True" 
       ObjectDataSourceID="objCustomersDS">
    </asp:GridView>
    
    <asp:ObjectDataSource ID="objCustomersDS" runat="server" 
         SelectMethod="GetAllCustomer" SelectCountMethod="GetAllCustomerCount" 
         TypeName="AssemblyName" EnablePaging="True" MaximumRowsParameterName="nbrOfResults"
         StartRowIndexParameterName="startIndex">
        <SelectParameters>
             <asp:Parameter Name="startIndex" Type="Int32" />
             <asp:Parameter Name="nbrOfResults" Type="Int32" />
             <asp:Parameter Direction="Output" Name="total" Type="Int32" />
        </SelectParameters>
    </asp:ObjectDataSource>
    
    • 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 GridView which has columns that look like this: | Foo
I have a form that contains a GridView control which is databound to an
I have GridView which I can select a row. I then have a button
I have a Gridview in which i have two templatefields of dropdownlist. I bound
I have a gridview to which I have created an Insert Template in the
I have a GridView control on an ASP page, which I've bound to a
I have a DataTable which is bound to a GridView. I also have a
I have a GridView control in an Asp.net application, that has a <asp:buttonField> of
I have a GridView where one column is bound to an object property containing
I have a Gridview, which is bound to an IList. I'd like to have

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.