Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 907
Mike Avatar asked Dec 13 '25 07:12

Mike


1 Answers

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.

like image 199
Alex Avatar answered Dec 15 '25 07:12

Alex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!