tags:

views:

234

answers:

3

How do I iterate through an IList collection and return only n number of records? I am trying to implement paging using an IList object.

+1  A: 
(From o As Object In myList).Take(n)

Hanselman has a good Paginated List class in his ASP .NET MVC tutorial here. You should check it out.

Brandon Montgomery
+2  A: 

Use the very useful PagedList:

http://blog.wekeroad.com/blog/aspnet-mvc-pagedlistt/

BFree
+1  A: 
foreach (int i in myList.Take(4))
{
            // do some stuff
}

It's worth noting that for pagination, you'll also want some sort of offset. To do so, you could do the following as well:

foreach (int i in myList.Skip(40).Take(20)) { }

In C#.

Tony k