473,776 Members | 1,498 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Gridview and effective paging

Hi everyone,

In a datagrid the entire data is read but only the page you want is
displayed to the user when you enable paging. Does the Gridview control
works in the same way?
So if you have 100000 records and you only want 10 records displayed on
each page, does it read all 100000 and display 10, or does it only read
what it needs (Read 10 and display 10)? If it reads all, I can't see
how this control can be useful for anything but small datasources?

Aug 28 '06 #1
3 2132
If you are allowing paging, then yes, every record is cursored
through....that 's the only way you can know how many records are available to
create the paging controls *UGH*

We all have our own solutions....he re's mine.......

if I want page 5...10 items per page....I execute 2 SQL statements on
seperate threads. one is a SELECT COUNT(*) and the other would be a SELECT
TOP 50
I execute read on the datareader 40 times and then return the datareader
which will have 10 records left.

Then set the number of pages for the grid and the data for the grid.

I used to so more exotic SQL for the data selection so that exactly 10
records were selected, but I found that the performance increase when doing
that is negligable for many (but not all) cases. That would be something
along the lines of

SELECT TOP 10 * from Customers where CustomerId not in (select top 40 from
customers)

things get a little hairy if you're filtering and sorting because you have
to put the same WHERE and ORDER BY clauses in the main query and the
subquery. BUT ... if you want the best possible performance and you need to
pass as little data as possible between tiers, that's the way to do it.

(I've had the same thought though......the GridView, and a lot of hte "UI
Magic" does make it wasy to build a BULKY application very quickly)

"ny***********@ gmail.com" wrote:
Hi everyone,

In a datagrid the entire data is read but only the page you want is
displayed to the user when you enable paging. Does the Gridview control
works in the same way?
So if you have 100000 records and you only want 10 records displayed on
each page, does it read all 100000 and display 10, or does it only read
what it needs (Read 10 and display 10)? If it reads all, I can't see
how this control can be useful for anything but small datasources?

Aug 28 '06 #2
Thank you for taking the time to answer me David!

David points out that we all have our own solutions... Can anybody else
tell me how you solve this? Whats your solution?

*Kalle*

David Jessee wrote:
If you are allowing paging, then yes, every record is cursored
through....that 's the only way you can know how many records are available to
create the paging controls *UGH*

We all have our own solutions....he re's mine.......

if I want page 5...10 items per page....I execute 2 SQL statements on
seperate threads. one is a SELECT COUNT(*) and the other would be a SELECT
TOP 50
I execute read on the datareader 40 times and then return the datareader
which will have 10 records left.

Then set the number of pages for the grid and the data for the grid.

I used to so more exotic SQL for the data selection so that exactly 10
records were selected, but I found that the performance increase when doing
that is negligable for many (but not all) cases. That would be something
along the lines of

SELECT TOP 10 * from Customers where CustomerId not in (select top 40 from
customers)

things get a little hairy if you're filtering and sorting because you have
to put the same WHERE and ORDER BY clauses in the main query and the
subquery. BUT ... if you want the best possible performance and you need to
pass as little data as possible between tiers, that's the way to do it.

(I've had the same thought though......the GridView, and a lot of hte "UI
Magic" does make it wasy to build a BULKY application very quickly)

"ny***********@ gmail.com" wrote:
Hi everyone,

In a datagrid the entire data is read but only the page you want is
displayed to the user when you enable paging. Does the Gridview control
works in the same way?
So if you have 100000 records and you only want 10 records displayed on
each page, does it read all 100000 and display 10, or does it only read
what it needs (Read 10 and display 10)? If it reads all, I can't see
how this control can be useful for anything but small datasources?
Aug 28 '06 #3
If you're using SQL2005 you can use the new ROW_NUMBER() function,
something like (using the pubs database)

use pubs;
go
with OrderedRows as
(select ROW_NUMBER() over (order by au_id) as row , au_id, au_lname,
au_fname from authors)
select * from OrderedRows
where row between 1 and 10
Kevin Jones

ny***********@g mail.com wrote:
Thank you for taking the time to answer me David!

David points out that we all have our own solutions... Can anybody else
tell me how you solve this? Whats your solution?

*Kalle*

David Jessee wrote:
>If you are allowing paging, then yes, every record is cursored
through....tha t's the only way you can know how many records are available to
create the paging controls *UGH*

We all have our own solutions....he re's mine.......

if I want page 5...10 items per page....I execute 2 SQL statements on
seperate threads. one is a SELECT COUNT(*) and the other would be a SELECT
TOP 50
I execute read on the datareader 40 times and then return the datareader
which will have 10 records left.

Then set the number of pages for the grid and the data for the grid.

I used to so more exotic SQL for the data selection so that exactly 10
records were selected, but I found that the performance increase when doing
that is negligable for many (but not all) cases. That would be something
along the lines of

SELECT TOP 10 * from Customers where CustomerId not in (select top 40 from
customers)

things get a little hairy if you're filtering and sorting because you have
to put the same WHERE and ORDER BY clauses in the main query and the
subquery. BUT ... if you want the best possible performance and you need to
pass as little data as possible between tiers, that's the way to do it.

(I've had the same thought though......the GridView, and a lot of hte "UI
Magic" does make it wasy to build a BULKY application very quickly)

"ny*********** @gmail.com" wrote:
>>Hi everyone,

In a datagrid the entire data is read but only the page you want is
displayed to the user when you enable paging. Does the Gridview control
works in the same way?
So if you have 100000 records and you only want 10 records displayed on
each page, does it read all 100000 and display 10, or does it only read
what it needs (Read 10 and display 10)? If it reads all, I can't see
how this control can be useful for anything but small datasources?

Aug 28 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2736
by: ck388 | last post by:
For some reason when I enable the callback feature of the gridview I still get a page refresh, that is it seems like there is a postback that occurs, not a callback which is just supposed to update not the whole page, but a portion of the page. Strangely enough the URL below http://beta.asp.net/QUICKSTARTV20/aspnet/doc/ctrlref/data/gridview.aspx (VB GridView Paging and Sorting Callbacks example)
2
16346
by: | last post by:
Hello, I have a GridView in my ASP.NET 2.0 application that performs the paging feature perfect when I have it bound to a data source. But now I have it bound to a dataset and the paging feature will not work. When I try to use paging I get this error: The GridView 'gvResults' fired event PageIndexChanging which wasn't handled.
1
2946
by: davidjgonzalez | last post by:
I have a GridView that has paging enabled. Each item (as defined in an ItemTemplate) includes several controls which have operations i would like to Atlas-enable. Everything is working well except when I page the GridView (the paging controllers are in the gridview's footer). The webpage doesnt scroll back to the top of the page, so when paging through the GridView the user is always looking at the last 4-5 items on the page. My current...
8
18090
by: Greg Lyles | last post by:
Hi all, I'm trying to develop an ASP.NET 2.0 website and am running into some real problems with what I thought would be a relatively simple thing to do. In a nutshell, I'm stuck on trying to display data in a "GridView" which is tied to an "ObjectDataSource". In turn, this ObjectDatasource gets it's data from a strongly-typed business object within my code.
2
13201
by: antonyliu2002 | last post by:
I've been googling for some time, and could not find the solution to this problem. I am testing the paging feature of gridview. I have a very simple web form on which the user can select a few fields to be included in the table, which is to be bound to the gridview. The web form looks like so (Don't worry about the stupidity of this web form for now.):
5
3007
by: Andrew Robinson | last post by:
I am attempting to better automate a Pager Template within a GridView. I am succesfully skinning a Drop Down List withing my control (the DDL is added to my control). I correctly populate the item list that corresponds with the number of pages, but I am unable to wire up the Selected Index Changed event. Auto PostBack is set to true and the page is posting back when the DDL is selected / chaged, but the event is never being called. Any...
0
2007
by: Don Miller | last post by:
Here is an example of what I believe is a bug in ASP.NET 2.0 GridView paging without postbacks (or at least not documented how to fix it). Once the GridView is displayed, clicking on any of the paging tools causes the GridView to completely disappear! This happens when either DataSets or DataTables are used (it doesn't work at all for DataReaders because they don't support paging apparently). If you remove the...
3
3743
by: Ronald S. Cook | last post by:
I was told that if calling lots of records from the database (let's say 100,000), that the GridView's paging feature would automatically "handle" everything. But the 100,000 records are still coming to the client, right? I mean, the paging feature isn't somehow making calls to the database for 25 records at a time or anything like that is it? I remember in the past having to write nasty stored procedures that took in
4
2729
by: Don Miller | last post by:
This is a repost of a reproducible problem/bug with GridView with dynamic SQL and binding. Is there a better ASP.NET newsgroup I should post to where MS techs or MVPs take an interest in such problems? Thanks. Here is an example of what I believe is a bug in ASP.NET 2.0 GridView paging without postbacks (or at least not documented how to fix it). Once the GridView is displayed, clicking on any of the paging tools causes the
0
9628
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10120
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10061
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9923
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8952
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6722
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5493
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4031
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2860
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.