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

  • Home
  • SEARCH
  • 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 4322444
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T08:52:27+00:00 2026-05-21T08:52:27+00:00

OK, so I understand how to use the ASP.net GridView control’s paging. You set

  • 0

OK, so I understand how to use the ASP.net GridView control’s paging. You set various methods to allow the control to get a subset of the data, and the number of records matched in total. Here’s my initialization code at the moment:

ObjectDataSource dataSource = new ObjectDataSource();
dataSource.EnablePaging = true;
dataSource.SelectParameters.Add(new Parameter("customerId", TypeCode.Int32, customerId.ToString()));
dataSource.SelectMethod = "SelectSomeRecords";
dataSource.StartRowIndexParameterName = "startRowIndex";
dataSource.MaximumRowsParameterName = "maximumRows";
dataSource.SelectCountMethod = "SelectAllRecordsCount";
dataSource.TypeName = "Name.Of.Data.Class";

grdUserList.DataSource = dataSource;
grdUserList.DataBind();

This works in that it passes the customer ID I’m displaying users for, as well as start row index and maximum rows, to my data class. But one thing puzzles me. Why does the control want a separate method for SelectCountMethod? At the database layer, I have a stored proc that returns the total number of matched rows as an output parameter as well as the subset requested. It would be a LOT easier if the DataGrid simply allowed my SelectMethod to return an int, indicating the total number of records matched before startRowIndex and maximumRows are applied.

This MSDN page seems to suggest (in its examples) that one should store the number of records in HttpRuntime.Cache, with an expiration time of 5 minutes. This seems to me like a far-from-perfect solution. You have potentially 5-minute-old data which may well have changed, when you could just be getting back the total number of records matched at the same time you call the SelectMethod! You’re going to want that information at the same time as you’re rendering the paged control, anyway.

My questions are, is there any way to get GridView to get its ‘all records count’ figure at the same time as it calls the ‘select method’, either through a return value or an out param? If not, how would you suggest working around this strange requirement for there being 2 methods for these 2 pieces of data, given that I will be getting my ‘all records count’ figure when I call SelectMethod? At the moment, I’m leaning towards storing that value in Session, setting it in SelectMethod, and just returning it in SelectCountMethod.

  • 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-21T08:52:28+00:00Added an answer on May 21, 2026 at 8:52 am

    Just to update, what I ended up doing was writing my own paging class and just providing one page of information to the GridView at a time. I found its built-in paging mechanism to be badly implemented. The additional benefit of using your own paging class is that you can use it with other ASP.net controls that don’t have built-in paging, like the Repeater.

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

Sidebar

Related Questions

I see another thread somewhat like my question at: ASP.NET GridView Column - formatting
I use ASP.NET and WCF services in a load balanced web server environment, using
I've been using ASP.NET (C#) for the past two years. I have learned so
Further to my question on disabling validators using javascript - Disable ASP.NET validators with
In ASP.NET Gridviews generate a table which generates a parent div container. This can
I'm currently converting our company database application from VB to ASP.NET. This is pretty
I am using asp.net MVC with the asp.net membership but I starting to think
What best practice or strategy would you use to enable bulk insert/update in an
I am working on a fairly large aspx web project with extensive use of
Very simple question but all the answer I read over the web doesn't apply.

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.