Implementing Paging in the ADO.NET Data Services Application

The current version of ADO.NET Data Services lacks a method for obtaining a count of records in a database table.  Such a method will be included in the next version, which is expected to be released this autumn.  In the meantime, this lack constrains the kinds of paging that can be used.  For this project, I just added a couple of hyperlinks to the tfoot section of my Presenters table, one with an id of PreviousPageLink, and the other with an id of NextPageLink.  In my stylesheet, I set the PreviousPageLink to float left, and the NextPageLink to float right.  For the first time in this project, I then had to write my own javascript.  I wrote a function that would be raised by the init event, and added handlers for clicks on PreviousPageLink and NextPageLink.


These handlers call the PreviousPage and NextPage functions respectively.  These two functions are very similar.  Since the DataView that displays the information about Mix presenters is an ASP.NET AJAX component, it takes the id of the DOM element to which it is attached, and can be found using ASP.NET AJAX’s $find method.  To make the Data Service return the correct page of data, we set two fetch parameters.  We saw fetch parameters in my previous post, where they were set with an attribute of the html element to which the DataView was attached.  In that case, we used only the $top parameter, which tells the Data Service how many records to return.  Now, in addition to $top, we are using $skip, which tells the Data Service to skip over so many records, and then return the number of records specified by the $top parameter.  The number of records to return at once is specified by the global ItemsPerPage variable.  The global CurrentPage variable keeps track of which page is currently being shown, and is used to calculate the value of the $top parameter.  Once the fetch parameters have been set, the fetchData method retrieves the required data and inserts it into our table.  The value of CurrentPage is then increased or decreased as appropriate. 

The only significant difference between the NextPage and PreviousPage functions is the existence in the latter of an if statement to determine when the first page is being displayed.  As mentioned above, ADO.NET Data Services has no count method, so it is impossible to know when the last page of data has been reached.  To get around this problem, I added an attribute in the html that adds a handler to the DataView’s fetchsucceeded event:


This calls the Succeeded function in the javascript above.  The data returned by the fetch is stored in the args object, and can be accessed with the get_result method.  If the length of this result is zero, I just call the PreviousPage function.

The result:



2 Responses to “Implementing Paging in the ADO.NET Data Services Application”

  1. Summaries 15.04.2009 « Bogdan Brinzarea’s blog Says:

    […] Implementing paging in ADO.NET Data Services application […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: