Easy DataGrid Paging with the DataGridPager
page 1 of 3
Published: 15 Feb 2005
Unedited - Community Contributed
Ever get tired of doing the same old stuff over and over again just to add paging to your DataGrid that looks nice and offers a lot of options to your users. Never fear, the DataGridPager is here to make your life easier! This article provides a short tutorial on using this nifty control to propel you on to more important development challenges.
by J. Ambrose Little
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 28956/ 45


[Download Sample]

A few years ago I got fed up with the less-than-desirable paging capabilities of the DataGrid.  Rather than go out and buy a custom control, I decided I’d just try my hand at building one that I could reuse across applications.  Thus was born the DataGridPager, my attempt at making DataGrid paging easier and better looking.  The control itself is available for free (source code available for only $50).  This article provides a small yet sufficient example that should answer most of the questions you might have about how to set up and use the control.

If you want to follow along yourself, go ahead and download the sample and extract it to a drive on a computer that has ASP.NET 1.1 installed.  Then just create a virtual directory in IIS called “DgpSample” that points to that directory on your drive.  At this point, you should be able to see the sample in action by navigating to http://localhost/DgpSample. Your screen should show something like Figure 1.

Figure 1 – DataGridPager in Action

Immediately you can see several key features:

1) You have first, previous, next, and last options (indicated by the angle brackets).  The display value for these can be customized.

2) You have Google-like direct page access to pages surrounding the currently-selected page.  You can customize the number of pages displayed before and after the current page.

3) There’s an item summary that tells you which items you are viewing and how many there are total.  You can customize the text here and choose display it above or below the pager links.  You can also not display it at all (default).

4) There are paging facilities above and below the DataGrid, and they look nice.  This is because rather than inheriting from the DataGrid and forcing one to use a custom DataGrid, I simply add to the DataGrid, allowing you to place as many pagers as you want wherever you want on the page.

View Entire Article

User Comments

Name: vinod
Date: 2008-06-03 11:17:44 AM
i can fill the datgrid with paging.
but while doing update or delete actiond on other pages records changing in the 1st page.
so can any 1 tel me how to use sessions by keeping the pageindex value and change the records.
Title: No Support Available   
Name: J. Ambrose Little
Date: 2008-04-18 2:15:39 PM
Hi folks,

I wrote this control about four years ago and this article over three years ago. I'm so far away from this code now, I am basically new to it myself. :)

It's a free component, and I can't afford to provide any more support for it. Sorry!

The source is still available for $50 (to be fair to those who have paid for it), so if you'd like the source, just contact me at ambrose [at] aspalliance [dot] com. Please know that the source is also as-is with no warranties, guarantees, and no support implied or otherwise.
Title: Custom paging works (kind of)   
Name: Matt
Date: 2008-04-18 12:24:09 PM
Thanks for this control! I am trying to impliment it using custom grid paging, in conjunction with a stored Oracle procedure supplying only the data that I need for one page at a time. I am setting the VirtualItemCount of the datagrid to the total number of items each time the data is bound to the grid. The VirtualItemCount is generally greater than the number of rows returned by the procedure. The problem I am having is with the button display of the pager. As you would expect, page 1 can't be selected initially, but even when you click ">>", it never becomes selectable, even though the data in the grid appears to page correctly. Any help with troubleshooting this would be helpful. Thanks!
Title: LChip dll   
Name: Nanu
Date: 2007-07-11 1:09:17 AM
From where i can get the dll required for the DataGridPager control? I couldnot find it inall my dlls list.
Title: problem   
Name: yasmin
Date: 2007-07-03 4:14:43 AM
I do what you say
but there is error that say
"Error Creating Control TopPager"
what the problem
Title: Unbind Pager   
Name: Dieter
Date: 2007-04-26 8:53:48 AM
I have this set up with a filter form that filters records from the database. I unbind the datagrid when I reset the form. How do I unbind the pager when I unbind the datagrid?
Title: GridView Version   
Name: Ambrose
Date: 2007-02-14 3:07:34 PM

I looked into the GridView back in alpha days, and it didn't appear to be a simple update, so I ditched the idea. The GridView itself has decent paging support via templates, so I didn't think the update worth the time. Also, there are some changes coming in Orcas that should provide more options.
Title: How about a gridview version   
Name: Joel Zinn
Date: 2007-02-14 11:29:45 AM
Ambrose. I have used this control for quite a while and have really enjoyed it. Since we are moving towards the new gridview control, have you thought about doing this same thing for the gridview?
Title: Stuck with error   
Name: jkolie
Date: 2006-11-15 5:07:27 AM
Iget this error System.Exception: Invalid CurrentPageIndex value. It must be >= 0 and < the PageCount.
Title: Thanx   
Name: sunny sinha
Date: 2006-08-28 7:04:29 AM
its a great way to cut down ur labour thanx a lot
Title: Need help   
Name: ranu
Date: 2006-08-10 1:24:27 AM
Nice control

thought of using it in my project but how will i include radio buttons inside this datagrid and onclick i want to delete the entire row

and want to fetch the datagrid items from database

can u pls help me out
Title: It's very easy   
Name: Prashant Kelkar
Date: 2006-08-02 2:18:38 AM
It's Very easy to use.
from now i am starting to use above code.
Title: RE: ItemSummaryText   
Name: Ambrose
Date: 2006-07-07 10:20:09 AM
Yeah, that's a format string, and I think it is:
0 - first item shown
1 - last item shown
2 - total items

SO in your case, it'd be something like:
Cars {0}-{1} of {2}
Title: ItemSummaryText   
Name: Ash
Date: 2006-07-07 6:24:16 AM
Nice controll.

Could you specify the values for ItemSummaryText? If I set value="Cars" it only shows "Cars". I want to show "Cars 10-20 of 30".

Title: cool control   
Name: prabhoda
Date: 2006-06-29 9:39:11 AM
this is a reealy cool control . thankx for the developers
Title: RE: Purchase Source   
Name: Ambrose
Date: 2006-05-16 9:45:41 AM
To purchase source code, send a PayPal payment to me at ambrose@aspalliance.com and follow up with an email to me to let me know where to send the code and where the payment is coming from.
Title: Buy Source   
Name: Andy Grimes
Date: 2006-05-11 11:45:46 AM
How can I buy the source to the control?
Title: ItemSummaryText issue   
Name: Andarial
Date: 2006-03-22 8:59:22 AM
n/m - I must have missed that other post of how he fixed it. Sorry!! *blush*
Title: ItemSummaryText issue   
Name: Andarial
Date: 2006-03-22 8:57:57 AM
Hi Ambrose, I really like your control - great work!

However, like Scott said a few posts up, I could use some help with the item summary text. I have 2 pages (12 items). On the first page it says "Items 1 - 1 of 1." On the 2nd page, it says "Items 11 - 1 of 1."

Also, the Item Summary Text is not centered like it is in your example.

Do you remember how you helped Scott? I would really like to use your control.

Thanks! : )
Title: great work!   
Name: Markus
Date: 2006-03-09 11:36:42 AM
Really great control! Thanks for sharing it!
Title: RE: Laura   
Name: J. Ambrose Little
Date: 2006-02-28 9:10:40 AM
Laura, I'd recommend downloading the sample and using it as a guide.
Title: HELP   
Name: Laura
Date: 2006-02-28 8:58:22 AM
i just cannot find where to put the first line in figure 4, i need to declare toppager first, right??
i am so lost...
Title: help   
Name: Newn kourne
Date: 2005-12-15 1:27:24 AM
Good control,Can you send it for me.I have not it....
Thank you! My e-mail:newsight886@163.com
Title: Huseyin   
Name: J. Ambrose Little
Date: 2005-10-21 6:34:56 PM
He figured it out on his own. It had something to do with using a drag-n-drop dataset for the datasource instead of doing it in code. I haven't had a chance to dig into it further myself.
Title: Items 11 - 1 of 1   
Name: Huseyin
Date: 2005-10-21 5:41:52 PM
Ambrose thanks for the dll, it saved a lot of time. Only problem I had is the page count and the last item index, whatever I do it always shows 1 of 1. Were you able to help Scott (who posted the same issue earlier)?


Title: Prashant   
Name: J. Ambrose Little
Date: 2005-10-20 5:54:04 PM
No, I don't use cache or session at all in this control.
Title: Internal Workign   
Name: Prashant Sharma
Date: 2005-10-20 5:47:57 PM
My question is : Does your control internally uses cache or session? Because that would put constraint on the server , otherwise it works gr8.
Title: Prashant   
Name: J. Ambrose Little
Date: 2005-10-20 5:01:42 PM
My control has nothing to do with how you handle your data. All that is standard ASP.NET stuff--you just have to rebind the grid in the page index change handler. You control how the grid is bound yourself.
Title: Great Contorl   
Name: Prashant Sharma
Date: 2005-10-20 4:05:22 PM
This controlhas saved hell lot of time. I've one query. Does it uses cache or session internally or every click brings records from the db. Actually, i was using a control earlier which was using cache. My application pulls 10K plus records from the db so using cache puts constraint on server resources. So i'm concerned, though i found that your control is much faster than earlier one.
Title: Scott   
Name: J. Ambrose Little
Date: 2005-10-19 5:03:12 PM
Sorry, Scott. I'm going to need to see more. Can you email your page and code behind to me at ambrose [at] aspalliance [dot] com?
Title: Thanks   
Name: scott
Date: 2005-10-19 4:55:55 PM
LCHIP:DataGridPager id="TopPager" runat="server" PagerGrid="dg" ItemCountStyle="Bottom" Width="760px"
CssClass="Pagers" UseConfigSettings="True" style="Z-INDEX: 102; LEFT: 48px; POSITION: absolute; TOP: 56px"
LastButtonText="Last" NextButtonText="Next" PreviousButtonText="Previous" FirstButtonText="First"
AddPageCount="5" PriorPageCount="5"></LCHIP:DataGridPager
Title: Scott   
Name: J. Ambrose Little
Date: 2005-10-19 4:44:40 PM
Scott, can you post your control markup here so I can see what's up with it?
Title: Good for the newb guy   
Name: Scott Baldridge
Date: 2005-10-19 4:36:53 PM
Thanks for the control. It fairly simple to use for the newb guy (me).

I could use some help with the item summary text. I believe that I have done everything corectly yet the only thing that is displayed is the first row of the page being displayed. For example, if paging is set to 10 and I am displaying page two then this is displayed "Items 11 - 1 of 1."
What can be done to correct this?
Title: Back color on the links   
Name: Dave
Date: 2005-09-08 11:26:52 AM
Hey, nice control. I just downloaded the sample but if I change the background color for the control it doesn't change it for the links (page numbers, next, first, etc). Is there a way to fix that?

Title: Image Buttons   
Name: J. Ambrose Little
Date: 2005-08-12 7:22:44 AM
As far as I can tell from the code (it's been a few years), it doesn't support image buttons as is. But on other controls I've built, I would allow people to specify "img:" to specify an image. If you had the source, you could modify the control to do that. :)
Title: imgage buttons   
Name: Jon
Date: 2005-08-12 2:41:21 AM
How can image buttons be used ?

Tried sending html code thru but it won't accept it .
Title: VB .NET   
Name: J. Ambrose Little
Date: 2005-06-14 11:24:09 PM
Well, this won't work at all with VBScript as this is an ASP.NET control. For VB.NET, it should work fine--you'll just need to run the sample code through one of the many C# to VB translators available for free on the web.
Title: will this work with vb   
Name: chris jones
Date: 2005-06-14 11:05:50 PM
I am a .net newbie so please excuse me if I am doing something silly, I have been trying to use your pager control with vb script. The sample code in C# works fine but I cannot complile it in vb. have you any ideas?
Title: RE: point   
Name: J. Ambrose Little
Date: 2005-05-26 11:42:30 AM
"coder," that's a silly thing to ask. The point is that you don't have to do that. This control provides extended paging functionality built for you. The point is the same as it is for all server controls--saving time through reuse. If you'd prefer to extend the datagrid yourself, more power to you.
Title: point   
Name: coder
Date: 2005-05-26 11:33:42 AM
whats the point in this. anyone with any amount of c# skill could add customisable paging buttons and just save it as an extended datagrid class?
Title: Control   
Name: Walter
Date: 2005-03-11 1:56:36 PM
Thanks Ambrose. I appreciate your help.

Title: It's There   
Name: J. Ambrose Little
Date: 2005-03-10 2:13:27 PM
Walter, the web.config file in the sample exemplifies how to do that. In the < PagerSettings /> section, you can add as many key/values as you want, but the keys must correspond to the property name on the pager that you want to set, so, in your case, you could just add something like:
< add key="FirstButtonText" value="<< First" />
< add key="LastButtonText" value="Last >>" />
< add key="NextButtonText" value="Next >" />
< add key="PreviousButtonText" value="< Previous" />
Title: Control   
Name: Walter
Date: 2005-03-10 1:58:19 PM
Great control. I'm using it now. Do you have an example of the we.confi where it shows the key for previous, next first and last values?
Title: Nice one   
Name: Sonu Kapoor
Date: 2005-02-25 10:10:19 AM
Nice control Ambrose. I think I can use it in my existing applications, where I dont have paging implemented yet. Saves coding time for me :) Thanks!

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-07-23 5:40:12 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search