Click here to Skip to main content
Click here to Skip to main content

Amazon-esque Pager

By , 29 Dec 2007
 

Screenshot - PagerControl.jpg

Sections

Introduction

There are quite a few pager controls out there. I haven't, however, found any that gives the choice to use either postbacks or plain hyperlinks. This control was born out of a wish to have paging that uses the traditional ASP.NET postback model on one page, and on another uses URL rewriting and caching. I also wanted chunking of page ranges, similar to the paging found on Amazon.com. This is my first article on CodeProject.

Overview

  • C# 2.0 UserControl.
  • Works with IE 6 and Firefox. Yet to be tested with other browsers.
  • Choose between LinkButton or Hyperlink rendering.
  • LinkButton mode allows for cancelation of page change during postback.
  • Supports multiple pagers on a single page.
  • Supports jumping to named anchors when using an ASP.NET AJAX UpdatePanel.
  • Supports string formatting of URLs in hyperlinks (URL rewriter friendly).
  • Customizable with CSS.

Background

In the past, I believe, ASP.NET has favoured rapid development over maintainability. The reason I mention this is that recently, there appears to be a shift within Microsoft towards a less ViewState/Postback oriented model. Whether this will render many of the postback dependent controls obsolete remains to be seen. This pager works happily in both situations: postback and non-postback. As an aside, I was disappointed to find that WF doesn't play well with ASP.NET. Without a hack, the back button breaks it (UIPAB anybody?). Could this be a missing feature/flaw to encourage the move to WPF? Who knows...

Like many, I have spent much time struggling with automagic controls; trying to bend them to my will. Frequently, I find that by using a Repeater rather than, say, a GridView, I am able to get what I want faster. With that in mind, this control is just UI. What I mean by that is that I haven't built any facility into this pager to allow for it to be databound, or coupled to a databound control such as a GridView. It is, however, easy to setup for use in conjunction with a data bound control.

Using the Code

  1. Copy the PagerControl's files from the provided web application project to your own web application project. The relevant files are those contained in the Controls subdirectory of the DemoWebsite project, and can be seen in the following image:
  2. Relevant files.

  3. Open or create a WebForm where you would like to place the pager, and drag PagerControl.ascx onto the page design surface. This will add a control source tag similar to the one shown below:
  4. <%@ Register Src="Controls/PagerControl/PagerControl.ascx" 
        TagName="PagerControl" TagPrefix="uc1" %>

    A PagerControl element will be added to your WebForm, like so:

    <uc1:PagerControl ID="PagerControl1" runat="server" />
  5. Set the ItemCount and ItemsPerPage properties of the PagerControl instance in the code-behind. Ordinarily, this will be done when data-binding or reading data from your data source.
  6. PagerControl1.ItemsPerPage = itemsPerPage;
    PagerControl1.ItemCount = itemCount;

    new Alternatively, if you wish to use the pager with a GridView, simply assign it a DataControlAdapter in the page Load handler. There is an example of how to do this in the GridViewDemo.aspx in the download. Once this is done, the pager will happily synchronize itself with the GridView instance.

    PagerControl1.DataControlAdapter = 
       new DataControlAdapter(gridView, itemCount);
  7. If using the PagerControl in LinkButton mode, which is the default, create an event handler for the PageChanged event, such as the following code example demonstrates:
  8. protected void PagerControl1_OnPageChanging(object sender, PageChangeEventArgs e)
    {
        int dataIndex = e.PageIndex * PagerControl1.ItemsPerPage;
        Repeater_DummyData.DataSource = 
          /* Get data using dataIndex and PagerControl1.ItemsPerPage*/
    
        Repeater_DummyData.DataBind();
    }

    And, wire it up to the PagerControl instance on the WebForm, like so:

    <uc1:PagerControl id="PagerControl1" 
       runat="server" OnPageChanging="PagerControl1_OnPageChanging">
  9. To use the PagerControl in Hyperlink mode, set the Mode property of the PagerControl instance in the designer. If the UrlFormat property has not been set in the designer, then the page index will be passed in the query string as a parameter named Page. The PagerControl keeps track of the current page index. We only need to load and bind the correct data to, e.g., a Repeater. For further information regarding the UrlFormat property and how it can be used with URL rewriting, please see Pager Properties.

N.B. The control will not be visible if the ItemCount property is less than 1.

Pager Browsable Properties

For the sake of simplicity, I have tried to limit the number of the pager's browsable properties. It is, after all, a User Control, and can be customised directly when it is copied to a project.

Browsable Pager properties

  • Anchor: The anchor that, when in LinkButton mode, will affect a jump to the anchor on the page. This property is intended to be used when the control is within an AJAX UpdatePanel.
  • Mode: Gets or sets the manner in which the PagerControl will be displayed. If the mode is LinkButton, then the pager will use postbacks to indicate that the page has changed. When the Hyperlink is used, all navigation will be done using hyperlinks, and the PageChanged event will not fire.
  • UrlFormat: The link URL format. An example value is http://www.example.com/Catalog/Products/{0}, where the format {0} parameter will be replaced by a page index value. If this value is not set, it will be defined as:
  • UrlFormat = string.Format("{0}?Page={{0}}", Request.Url.AbsolutePath);

    where the current page index will be passed as a QueryString parameter called Page.

Localised Resources

PagerControl uses a Global resource file Site.resx. This is how I tend to do localisation. I find that creating a local resource file for a page or a control ends up being more difficult to manage. The following image shows the text values that can be customised/localised.

Pager Resource file.

Points of Interest

Control Base Class

The PagerControl class extends UserControlBase. UserControlBase provides some auxiliary methods, such as for retrieving values from the ViewState and the Request QueryString instance. As you will see, many of these methods are overloaded. You may choose to remove the PagerControl's dependency on the base class if it is does not match your current class hierarchy. The following is an example of one such method:

public int GetViewStateValue(string stateKey, int defaultValue)
{
    object stateValue = ViewState[stateKey];
    int result;
    if (stateValue == null)
    {
        result = defaultValue;
    }
    else

    {
        result = int.Parse(stateValue.ToString());
    }
    return result;
}

AccesKeys

I was keen to add some page shortcuts for the next and previous navigation. Unfortunately the AccessKey attribute of an element does work too well. Well, it didn't for me anyway in IE 6 and FF 2. We will leave a JavaScript solution to a later iteration. For now, next and previous are assigned the AccessKeys 2 and 1 respectively.

CSS and Enabled = false

When testing the control in IE and Firefox, I quickly realised that the two browsers display anchors differently when the disabled attribute is used. As it turns out, IE ignores some styles such as color when a link is disabled. Firefox, on the other hand, does not. So, it was necessary to create a style for disabled links.

a.PagerDisabled
{
    border:none;

    color:Gray;
    background: transparent;
    padding:6px;

}

Conclusion

Well, I hope you find this control useful. If so, then you may like to rate it and/or leave feedback below.

History

  • October 2007
    • First release.
  • December 2007
    • Added GridView support.
    • Page range logic improved.

License

This article, along with any associated source code and files, is licensed under The BSD License

About the Author

Daniel Vaughan
Software Developer (Senior) Outcoder
Switzerland Switzerland
Member
Daniel Vaughan is a Microsoft MVP and cofounder of Outcoder, a Swiss software and consulting company dedicated to creating best-of-breed user experiences and leading-edge back-end solutions, using the Microsoft stack of technologies--in particular Silverlight, WPF, WinRT, and Windows Phone.
 
Daniel is the author of Windows Phone 7.5 Unleashed, the first comprehensive, start-to-finish developer's guide to Microsoft's Windows Phone 7.5.
 
Daniel is also the creator of a number of open-source projects, including Calcium SDK, and Clog.
 
Would you like Daniel to bring value to your organisation? Please contact

Daniel's Blog | MVP profile | Follow on Twitter
 
Windows Phone Experts

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralParse Error MessagememberMember 181694916 Apr '09 - 15:19 
I'm just compile and I'm getthis message.
 
Parser Error Message: Could not load file or assembly 'System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
 
Source Error:
 

Line 27: <compilation debug="true">
Line 28: <assemblies>
Line 29: <add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
Line 30: </assemblies>
Line 31: </compilation>
GeneralPager and SqlDataSource or ObjectDataSourcememberDejan]29 Mar '09 - 2:43 
How to use this if I bind DataList with SqlDataSource or ObjectDataSource? I don't have code-behind bindong of datalist control.
      <asp:sqldatasource id="SqlDataSource1" runat="server" xmlns:asp="#unknown">
            ConnectionString="<%$ ConnectionStrings:mYConnectionString %>" 
            SelectCommand="SELECT * FROM [table]"></asp:sqldatasource>
    
    
    <asp:datalist id="DataList1" runat="server" datakeyfield="id" xmlns:asp="#unknown">
        DataSourceID="SqlDataSource1">
        <itemtemplate>
            id:
            <asp:label id="id" runat="server" text="<%# Eval("id") %>" />
            <br />
            kat:
            <asp:label id="katLabel" runat="server" text="<%# Eval("kat") %>" />
        </itemtemplate>
    </asp:datalist>
    <uc1:pagercontrol id="PagerControl1" runat="server" itemsperpage="10" mode="Hyperlink" xmlns:uc1="#unknown" />
This doesn't work.
GeneralProblem with Visual Web Developer 2008 Expr. Editionmembermartinvdm13 Oct '08 - 3:23 
Hi Daniel,
 
I would like to use your control but encounter the following problem converting it to VWD2008 Express edition.
I had to place the DataControlAdapter.cs, PageChangeEventArgs.cs, UserControlBase.cs in the App_Code folder. Doing this it is not possible anymore to instantiate from the PagerControl in the DataControlAdapter, because it sits outside of the App_Code folder.
 
public class DataControlAdapter
{
GridView gridView;
 
int pageIndex;
int itemCount;
int itemsPerPage;
 
---> PagerControl pagerControl;
 
public PagerControl PagerControl
{
get
{
return pagerControl;
}
set
 
Do you know how I can solve this problem?
 
Many thanks.
GeneralRe: Problem with Visual Web Developer 2008 Expr. EditionmvpDaniel Vaughan13 Oct '08 - 4:35 
Hi Martin,
 
Are you using Service Pack 1? I ask because Visual Web Developer 2008 Express Edition SP1 now has support for Web Application Projects. If you use a Web Application as opposed to a Website, you shouldn’t have too many problems. Otherwise you will have to fiddle a bit to get it working.
 
Cheers,
Daniel
 
Daniel Vaughan



Blog: DanielVaughan.Orpius.com



GeneralRe: Problem with Visual Web Developer 2008 Expr. Editionmembermartinvdm13 Oct '08 - 6:26 
Hi Daniel,
 
Thanks for your fast reply. I will upgrade to SP1 and try again.
 
Best regards
QuestionProblem using control with VS 2008memberlplates6 May '08 - 1:20 
Daniel,
 
This control looks great and I'd like to use it in one of my projects. However, I'm having trouble getting the control to work in a Visual Studio 2008/Framework 3.5 web site. When attempting to build the web site I receive:
 
Could not load type 'Orpius.Web.Controls.PagerControl'. PagerControl.ascx Line 1
 
I'm not sure what's causing this as your demo project runs ok when converted to VS 2008. Can you offer some advice on this?
 
You ought to be able to replicate the behaviour using the following steps:
 
1. From within VS 2008, create a new web site. I used a file system site but I doubt it matters.
2. Copy the Controls folder from your demo site to the root of the new site.
3. Copy the App_GlobalResources folder from your demo site to the root of the new site.
4. Attempt to build the site. Error should appear.
 
Thanks in advance.
Dave
GeneralRe: Problem using control with VS 2008mvpDaniel Vaughan7 May '08 - 1:31 
Hi Dave,
 
I followed your steps and found that I was able to recreate the website by first converting it to 2008, then copying the converted files to a newly created ASP .NET Web application. Make sure that all the designer files are included in the project.
 
Daniel
 
Daniel Vaughan



Blog: DanielVaughan.Orpius.com



GeneralElement 'PagerControl' is not a known element [modified]membergwad64525 Mar '08 - 15:56 
Hi,
 
The control looks awesome and I would love to use it however I'm doing
something wrong or there is a problem with my configuration.
 
I am using Visual Web Developer Express 2005 (VWD) and building a wep app with a gridview.   I have placed all files as per the instructions and dragged the control file to the design surface of the form.   It shows the PagerControl tags with the red squiggle error, the error message is the subject line of this msg.
 
Also, a new line is shown at the top of the page source listing:
 
<%@ Register Src="Controls/PagerControl/PagerControl.ascx" TagName="PagerControl" TagPrefix="uc1" %>
................................
VWD error after website build states: Could not load type 'Orpius.Web.Controls.PagerControl'.  
 
File: PagerControl.ascx
 
Line: 1
.............................
 
Please let me know if you can help.
 
Thanks,
Dawg
 
modified on Tuesday, March 25, 2008 10:02 PM
GeneralRe: Element 'PagerControl' is not a known elementmvpDaniel Vaughan25 Mar '08 - 23:07 
Hi Dawg,
 
So the class Orpius.Web.Controls.PagerControl isn’t being resolved. Is the namespace of the PagerControl.ascx.cs equal to Orpius.Web.Controls? Is the Build Action of the file set to 'Compile'?
 
Daniel Vaughan



Blog: DanielVaughan.Orpius.com



GeneralPagerControl Doesn't load properlymembersassiecode24 Mar '08 - 10:44 
I am getting this error
 
Could not load type orpius.web.controls.pagercontrol when I try to complile the demosite. I actually don't know why I am getting this error and not sure how I can get rid of it. It is on the Inherits line of the Page directive.
 
<![CDATA[<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="PagerControl.ascx.cs" Inherits="Orpius.Web.Controls.PagerControl" %>]]>
 
Seems to me the path is fine.
 
Is the demosite in a state it can be ran when loaded into V5?
GeneralRe: PagerControl Doesn't load properlymvpDaniel Vaughan24 Mar '08 - 20:48 
The demo site is buildable and runnable. I just downloaded and tested it on another PC using VS 2005 SP1.
Is the build action property of the PagerControl.ascx.cs file set to Compile?
I would try downloading it again.
Let me know how you go.
 
Daniel
 
Daniel Vaughan



Blog: DanielVaughan.Orpius.com



GeneralVery Nicemembermerlin98131 Dec '07 - 4:06 
This is very nice. Thank you for sharing
 


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Rhabot - World of Warcraft Bot

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

GeneralRe: Very NicememberDaniel Vaughan31 Dec '07 - 4:40 
Thanks merlin981. I'm glad you like it. Smile | :)
 



Daniel Vaughan


LinkedIn Profile
ShelfSpy

GeneralProblem using the controlmemberDUMITRU Guraliuc20 Nov '07 - 5:51 
Hi,
 
I am trying to add the control to a VS2005 web site by manually copying it as described.
However when compiling the solution I get some errors related to <%=Resources.Site.Controls_Pager_PreviousLink%> not being accessable.
 
Please advice.
GeneralRe: Problem using the controlmemberDaniel Vaughan20 Nov '07 - 12:58 
Hi Dumitru,
 
thanks for telling me about this. Copy the Site.resx file to your App_GlobalResources directory. I didn't mention this in the steps to setup the control, so I'll do an update soon.
 
Daniel
 

 





Daniel Vaughan
LinkedIn Profile
ShelfSpy

GeneralRe: Problem using the controlmemberDUMITRU Guraliuc20 Nov '07 - 20:26 
Thank you Daniel.
It is ok now. Very nice control.
QuestionHow to Use with GridViewmemberthomasswilliams21 Oct '07 - 14:24 
Hi Daniel - thanks for the article and pager component. I have two comments:
1. It would be helpful to have a version without the ASP.NET AJAX stuff.
2. I'm interested in how would you use this, with a bound Grid View (ASP.NET 2.0)?
 
For number 1, taking out the AJAX stuff seems fairly simple - replace web.config with a version without AJAX, remove the reference to the "extensions" dll, remove the "scriptmanager" component in the master template, and some more changes. I only ask because we don't yet have ASP.NET AJAX instaled on our production servers.
 
For number 2, I work with Grid Views but find the in-built paging barely practical. Your component is 10x better (and a lot better looking) Smile | :)
 
Cheers,
 
Thomas Williams
http://dotnetjunkies.com/WebLog/thomasswilliams/
AnswerRe: How to Use with GridViewmemberDaniel Vaughan21 Oct '07 - 16:14 
Hi Thomas,
 
Thanks for your kind comments.
 
1. That will do the trick. I haven&apos;t included anything custom in the web.config. You may also want to delete LinkButtonModeWithAjax.aspx
 
2. That&apos;s a good point. I will include that in the next update.
 
To use a GridView set the AllowPaging property of the GridView instance to true.
Set the GridView&apos;s PagerSettings Visible property to false.
In the PagerControl1_OnPageChanging handler set the PageIndex of the GridView to the PageChangeEventArgs PageIndex property, and then call DataBind() on the GridView.

I have just finished a GridView demo. For now I will post the source here for you.
 
Create a new WebForm GridView.aspx.
 
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="GridView.aspx.cs" Inherits="Orpius.Web.GridView"
MasterPageFile="~/Site.Master"
%>
 
<%@ Register Src="Controls/PagerControl/PagerControl.ascx" TagName="PagerControl"
     TagPrefix="Orpius" %>
 
<asp:Content ID="Content_Main" runat="server" ContentPlaceHolderID="ContentPlaceHolder_Content">
     <div style="margin-bottom:20px">
          <asp:GridView ID="GridView_DummyData" runat="server" AllowPaging="True">
               <PagerSettings Visible="False" />              
          </asp:GridView>
     </div>
     <div style="margin-bottom:20px">
          <Orpius:PagerControl id="PagerControl1" runat="server" OnPageChanging="PagerControl1_OnPageChanging">
          </Orpius:PagerControl>
     </div>          
</asp:Content>
 

GridView.aspx.cs looks like this:
 
using System;
using System.Collections.Generic;
using Orpius.Web.Controls;
 
namespace Orpius.Web
{
     public partial class GridView : System.Web.UI.Page
     {
          static int itemCount = 50;
 
          List<DummyDataItem> dummyData = new List<DummyDataItem>(itemCount);
 
          protected void Page_Load(object sender, EventArgs e)
          {
               LoadDummyData();
               GridView_DummyData.DataSource = dummyData;
 
               if (!IsPostBack)
               {
                   
                    GridView_DummyData.DataBind();
 
                    PagerControl1.ItemsPerPage = GridView_DummyData.PageSize;
                    PagerControl1.ItemCount = dummyData.Count;
               }
          }
 
          void LoadDummyData()
          {
               dummyData.Clear();
               for (int i = 1; i <= itemCount; i++)
               {
                    DummyDataItem item = new DummyDataItem("Item " + i);
                    dummyData.Add(item);
               }
          }
 
          protected void PagerControl1_OnPageChanging(object sender, PageChangeEventArgs e)
          {
               GridView_DummyData.PageIndex = e.PageIndex;
               GridView_DummyData.DataBind();
          }
     }
}
 
Daniel Vaughan
GeneralRe: How to Use with GridViewmemberthomasswilliams22 Oct '07 - 16:52 
Cheers Daniel, this really helped me on my way.
 
Best of luck with your future developments!
 
Thomas Williams
http://dotnetjunkies.com/WebLog/thomasswilliams/
GeneralRe: How to Use with GridView [modified]memberDUMITRU Guraliuc21 Nov '07 - 2:33 
Hi Daniel,
 
if you don't mind I have a small sugestion to make.
 
I have the following case:
I need to use your pager with a GridView that has an ObjectDataSource with custom paging enabled.
 
This means that I can set the PagerControl1.ItemCount property, only, after the ObjectDataSource executed the SelectCountMethod="GetRecordCount" method.
So, the total number of records in the database is available only after the "Selected" event of the ObjectDataSource is fired.
 
The issue is that, this event is fired after the Page_Load event of the page (and also of the PagerControl).
Checking your source code I noticed that the UpdatePager(PageIndex) method is called in Page_Load, at which time the ItemCount propery is 0.
 
By calling the UpdatePager(PageIndex) in OnPreRender, the Pager's properies can be set up at later stages than Page_Load.
 
For instance:

protected void objDs_Selected(object sender, ObjectDataSourceStatusEventArgs e)
{
// --- We might have the SelectedCount executed so we process the number of total records.
try
{
int nCount = System.Convert.ToInt32(e.ReturnValue);
PagerControl1.ItemsPerPage = GridView.PageSize;
PagerControl1.ItemCount = nCount;
}
catch (Exception ex)
{
// do nothing as nothing bad happend
}
}

 
Another small issue: the Panel_Pager.Visible = ItemCount > ItemsPerPage need to be called also in OnPrerender.
 
One more time: great job with this control.
Regards.
 

 

 
-- modified at 8:45 Wednesday 21st November, 2007
GeneralRe: How to Use with GridViewmemberDaniel Vaughan21 Nov '07 - 14:45 
Thanks Dumitru.
 
I'll include this in the next update, and I really appreciate your input.
 
Cheers,
Daniel
 





Daniel Vaughan
LinkedIn Profile
ShelfSpy

GeneralRe: How to Use with GridViewmembernh@zonith.com10 Dec '07 - 11:10 
Hi Daniel,
 
First of all, thank you very much for creating a pager that is worth (well worth) including in a product. The standard pager simply is not good enough for a professional solution in my opinion.
 
On my project I was introduced your pager after reading a bit about it. It was very easy to insert into my existing GridViews, however I had to make some modifications to make it work correctly (special cases). The first thing I had to do was the same a Dumitru, since I had some things I wanted to set up before the rendering, so I moved some code (actually all of your Page_Load(object sender, EventArgs e) content) to the OnPreRender(EventArgs e) method. This solved some of the problems.
 
One last problem remained: I am using the pager for a GridView (actually several) where you can edit/update/delete the rows "inline" so to speak. Edit/update did not pose a problem, however Delete did in the extreme (last page) case.
 
Consider the following:
You have a GridView with a page size of 2, you have a total of 3 rows to display. You navigate to the second (and last) page and view 1 row. Here you click on Delete to delete the last row. Now the pager (naturally) was very confused since I was on a page which did not exist, and the calculation was just messed up big time. It displayed "showing 3 to 4 ..." even though only 2 rows were present (and NOT shown).
 
To deal with that situation I had to make a few modifications.
 
1. Move the Page_Load(object sender, EventArgs e) content to the OnPreRender(EventArgs e) method
2. Introduce a variable, moveBackOnePage which determines if the pager should jump back one page before rendering.
3. Always set the variable moveBackOnePage to false in the Page_Load(object sender, EventArgs e)
4. Create a new method, MoveBackOnePage() which sets the moveBackOnePage variable to true.
5. At the bottom of the OnPreRender(EventArgs e) right before UpdatePager(PageIndex); I check if the moveBackOnePage variable is set, and if so I decrement the PageIndex by one. (if (moveBackOnePage) { PageIndex -= 1; }
 
That was all I had to change in your pager code. However there was still one task left to finish the job. Everytime I had to (re)display the page, I now had to check if I was currently on the last page (and NOT the first - they can be the same) and if I deleted the last entry on the page. To implement this, I simply extended on Dimitrus thoughts and ended up with the following code in my page codebehing file:
 

protected void ObjectDataSource1_Selected(object sender, ObjectDataSourceStatusEventArgs e)
{
// We might have the SelectedCount executed so we process the total number of records.
try
{
int nCount = System.Convert.ToInt32(e.ReturnValue);
PagerControl1.ItemsPerPage = TheGridView.PageSize;
PagerControl1.ItemCount = nCount;
 
// Figure out which page is the last
int lastPage = PagerControl1.ItemCount / PagerControl1.ItemsPerPage;
 
// Find the number of rows displayed on the last page
int rowsOnLastPage = PagerControl1.ItemCount % PagerControl1.ItemsPerPage;
 
// If we are on the last+ page (and not the first! - if only one page is available)
if (PagerControl1.PageIndex > 0 && PagerControl1.PageIndex >= lastPage)
{
// If we are on a page larger than the last OR we are on the last page but there are no rows
if (PagerControl1.PageIndex > lastPage || rowsOnLastPage == 0)
{
// Move the pager back one page to display the "real" last page.
PagerControl1.MoveBackOnePage();
}
}
}
catch (Exception)
{
// do nothing as nothing bad happened. This is due to 2 calls to this method
// where only one of them performs the right task, and the other throws an exception
// which we don't care about
}
}

 
As the code shows I determine in which situations it is appropriate to move the pager back one page before rendering it. As this is called after the Page_Load(object sender, EventArgs e) method of the pager but before the OnPreRender(EventArgs e) method, we can safely do it. The approach above may not be the prettiest solution, but it solved my problem. I hope it can inspire you to think about the problem, and maybe integrate a solution into your pager if possible. I think it requires some interaction between the codebehind of the page holding the pager, and the pager itself, but maybe you can figure out something neat Cool | :cool: .
 
By the way, I modified the control to work with the Theme my project is using, and doing so was very easy thanks to the CSS classes you defined, and the simple background image. Great job!
 
Thanks again for a very nice control!
 
Regards,
Nicolai
GeneralRe: How to Use with GridViewmemberDaniel Vaughan10 Dec '07 - 13:53 
Hi Nicolai,
 
Thank you for taking the time to write me a detailed message about your exploits with the control.
 
The control should obviously be able to cope with the scenario you describe. I haven’t used it with a GridView yet, so I didn’t spot that. Sounds like it required a bit of hacking to bend it to your will eh. Smile | :)
 
As you suggest, I will try to come up with an integrated solution to the problem in an update (which is now very overdue!).
 
Thanks again Nicolai.
 
Kind regards,
Daniel
 



Daniel Vaughan


LinkedIn Profile
ShelfSpy

GeneralRe: How to Use with GridViewmemberDaniel Vaughan29 Dec '07 - 21:38 
I have updated the control. Thank you very much for your feedback.
 



Daniel Vaughan


LinkedIn Profile
ShelfSpy

GeneralRe: How to Use with GridViewmemberMember 39982585 Jun '09 - 6:36 
thanks alote
Nicolai
i need your code if you can
becouse i tried but not work
 
Please send me source code
to
"
On my project I was introduced your pager after reading a bit about it. It was very easy to insert into my existing GridViews, however I had to make some modifications to make it work correctly (special cases). The first thing I had to do was the same a Dumitru, since I had some things I wanted to set up before the rendering.
"
 
i have same case
Please....
 
thanks alot
 
Ahmad

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 30 Dec 2007
Article Copyright 2007 by Daniel Vaughan
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid