Bind GridView with many records

前端 未结 1 632
醉话见心
醉话见心 2021-01-16 11:09

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 i

1条回答
  •  难免孤独
    2021-01-16 11:46

    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;
    }
    
    /// 
    /// This methods must have the same signature than the "real" one... exept the name :oP
    /// 
    public static int GetAllCustomerCount(int startIndex, int nbrOfResults, out total) {
          return (from c in data.Customers select c).Count();
    }
    

    And now in your page ;

    
    
    
    
        
             
             
             
        
    
    

    0 讨论(0)
提交回复
热议问题