asp.netpaginationrepeater

Paging in ASP.NET without a database


I have a page on my ASP.NET site that has a Repeater control to show posts from members of the site.

At the moment I am storing the data for the posts in an XML file and then caching it within the site inside custom objects.

So I have:

public class MemberPost
{
    public string Title { get; set; }
    public string Text { get; set; }
    public string Name { get; set; }
    public DateTime Date { get; set; }
    public List<string> Pictures { get; set; }
}

And:

public class MemberPosts : List<MemberPost>
{

}

I'm able to set the data source of the repeater to an instance of MemberPosts and it all works as expected, but I want to add paging for when more posts are added.

All the examples I find seem to involve having the data to be paged in a database - is there any way I can bind the repeater or another similar control to my in-memory MemberPosts collection and have it implement paging for me?

I'm using VS2010 / .NET 3.5, but can switch to 4.0 if necessary as I have that on my server.

Thanks.


Solution

  • http://msdn.microsoft.com/en-us/library/bb358985.aspx

    http://msdn.microsoft.com/en-us/library/bb503062.aspx

    those are the 2 methods in IEnumerable you need.

    You got

    yourList.Skip(5).Take(5)

    to show the second page of 5 items.