CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Format:
Recent snippets matching tags of paging
C#
/// <summary>
/// Returns a page worth of items from the specified collection.
/// </summary>
/// <typeparam name="TSource">the type of the items in the collection</typeparam>
/// <param name="source">an IEnumerable&gt;TSource&lt; of items to page</param>
/// <param name="pageNumber">the number of the page to return</param>
/// <param name="itemsPerPage">the number of items that make up a page</param>
/// <returns>
/// An IEnumerable&gt;TSource&lt; the contains the specified number of items for the specified pageNumber. 
/// If pageNumber exceeds the number of available pages, the returned collection will be empty.
by Al Gonzalez   March 15, 2010 @ 9:59am
Tags: LINQ, Skip, Take, Paging
298 Views
no comments
 
C#
public static List<T> Page<T, TResult, TResult1>(this List<T> obj, int page, int pageSize,
        System.Linq.Expressions.Expression<Func<T, TResult>> keySelector,
        bool asc, out int rowsCount, bool isThenBy, System.Linq.Expressions.Expression<Func<T, TResult1>> thenByClause)
    {
        rowsCount = obj.Count();
        if (asc)
        {
            if (isThenBy)
                return obj.AsQueryable().OrderBy(keySelector).ThenBy(thenByClause).Skip((page == 0 ? 0 : page - 1) * pageSize)
                            .Take(pageSize).ToList();
by Giuliano Lemes   July 28, 2009 @ 6:19am
Tags: Linq, paging
550 Views
no comments
 
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate