Geeks With Blogs
Daren Kovacevic blog
I was tasked to build an rss reader the other day and created a Datalist to display the output. I wanted to display page numbers but then realised that the datalist doesn't have any built in functionality for paging (like the DataGrid and GridView). I was faced with the prospect of rolling my own until I realised that most of the work had already been done for me with the PagedDataSource class! This neat class gives me all of the same functionality as native paging, and was easy to setup. It includes all of the important ingredients to do my own paging such as properies for.....PageSize, PageCount, IsFirstpage, IsLastPage etc. Here is a chunk of my code....

PagedDataSource pagedItems = new PagedDataSource();

pagedItems.DataSource = myArrayList; //the datasource
pagedItems.AllowPaging = true;
pagedItems.PageSize = maxItems;
pagedItems.CurrentPageIndex = Int32.Parse(Request.QueryString["page"]);
catch (Exception ex)
pagedItems.CurrentPageIndex = 0;
lblPages.Text = "";

if (pagedItems.PageCount > 1)
for (int x = 1; x < pagedItems.PageCount + 1; x++)
lblPages.Text += "
+ "page=" + (x - 1) + ">" + x.ToString() + "";
Posted on Monday, May 22, 2006 1:56 AM .NET | Back to top

Comments on this post: Paged Data Source Class

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Daren Kovacevic | Powered by: