A Beginner's Question About How GridView Paging Gets It's Data

Hey,

I hoping someone could answer a question for me. I am relatively new to developing web applications with .NET and I have question I can’t seem to find a straight answer to.

When allowing paging of a GridView control, how does retrieve the data per-page? Is all the data stored into an object, and then displayed x amount of rows at a time? Or, when moving from page to page, is it executing each time but restraining the result to the specified amount of rows?

Yes, I never use the built in paging. If you using caching, then it will do it once and just page that object.

But paging with custom result sets is the best for performance

Grid View is a custom data bound control of .Net
use for displaying number of rows of a bounded
table .
if the rows are in large number then you can set
allowpaging property to true .it breaks your grid
view in number of pages.
the number of pages will be depend upon the
number which you have specified in pagesize
property.
In actual the data of retrieved from database
stored in an object known as object view.

Unfortunately that’s the way the gridview paging works :slight_smile:

When I step through the code using Using Visual Studio’s debugger tool, I see that the query is being executed and returning the same amount of rows (in this case 247) with every “paged” page view – regardless of what the PageSize property is set to (in this case 50).

Could happen lots of ways–there are a few layers of indirection. Best bet is to watch what is happening on the data tier using whatever instrumentation is available to see how much is getting returned.

Thank you for the response.

If I understand you, though the data returned from the initial query (say 500 rows) is stored into an object for paging (say 100 rows per page), the application is still going to execute the query with every page load? Wouldn’t this negate any advantage to using the GridView’s “built in” paging functionality altogether?

I will have to look into custom paging a little further.

It is storing all the results in an object and just show x amount of rows. Thus why if you have a large amount of data, you will start getting major performance issues. As it also gets the data every time the pager is loaded. Best is to do custom paging, maybe with Linq 2 Sql or other ORM and get only the results you need