Click here to Skip to main content
15,891,136 members
Articles / Web Development / ASP.NET

Repeater with Paging and Sorting Features

Rate me:
Please Sign up or sign in to vote.
4.78/5 (17 votes)
16 Jul 2009CPOL3 min read 104.3K   4.3K   55  
Repeater with Paging and Sorting features
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Class provides the Extension methods for sorting UserInfo collection
/// </summary>
public static class Extension
{
    /// <summary>
    /// Sorts the elements of a UserInfo collection on UserName
    /// </summary>
    /// <param name="userList">A Collection of  UserInfo to order</param>
    /// <param name="isAscending">A boolean to decide the ascending or descending order</param>
    /// <returns>A collection of UserInfo whose elements are sorted according to a key and order.</returns>
    public static IList<UserInfo> OrderByUserName(this IList<UserInfo> userList, bool isAscending)
    {
        if (isAscending)
            return userList.OrderBy(a => a.UserName).ToList();
        else
            return userList.OrderByDescending(a => a.UserName).ToList();
    }

    /// <summary>
    /// Sorts the elements of a UserInfo collection on FirstName
    /// </summary>
    /// <param name="userList">A Collection of  UserInfo to order</param>
    /// <param name="isAscending">A boolean to decide the ascending or descending order</param>
    /// <returns>A collection of UserInfo whose elements are sorted according to a key and order.</returns>
    public static IList<UserInfo> OrderByFirstName(this IList<UserInfo> userList, bool isAscending)
    {
        if (isAscending)
            return userList.OrderBy(a => a.FirstName).ToList();
        else
            return userList.OrderByDescending(a => a.FirstName).ToList();
    }

    /// <summary>
    /// Sorts the elements of a UserInfo collection on LastName
    /// </summary>
    /// <param name="userList">A Collection of  UserInfo to order</param>
    /// <param name="isAscending">A boolean to decide the ascending or descending order</param>
    /// <returns>A collection of UserInfo whose elements are sorted according to a key and order.</returns>
    public static IList<UserInfo> OrderByLastName(this IList<UserInfo> userList, bool isAscending)
    {
        if (isAscending)
            return userList.OrderBy(a => a.LastName).ToList();
        else
            return userList.OrderByDescending(a => a.LastName).ToList();
    }

    /// <summary>
    /// Sorts the elements of a UserInfo collection on Password
    /// </summary>
    /// <param name="userList">A Collection of  UserInfo to order</param>
    /// <param name="isAscending">A boolean to decide the ascending or descending order</param>
    /// <returns>A collection of UserInfo whose elements are sorted according to a key and order.</returns>
    public static IList<UserInfo> OrderByPassword(this IList<UserInfo> userList, bool isAscending)
    {
        if (isAscending)
            return userList.OrderBy(a => a.Password).ToList();
        else
            return userList.OrderByDescending(a => a.Password).ToList();
    }

    /// <summary>
    /// Sorts the elements of a UserInfo collection on LastLoginDate
    /// </summary>
    /// <param name="userList">A Collection of  UserInfo to order</param>
    /// <param name="isAscending">A boolean to decide the ascending or descending order</param>
    /// <returns>A collection of UserInfo whose elements are sorted according to a key and order.</returns>
    public static IList<UserInfo> OrderByLastLoginDate(this IList<UserInfo> userList, bool isAscending)
    {
        if (isAscending)
            return userList.OrderBy(a => a.LastLoginDate).ToList();
        else
            return userList.OrderByDescending(a => a.LastLoginDate).ToList();
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Team Leader Softweb Solutions
India India
Profiles : Code Project, ASP.NET Forums
Blog : Knowledgebase World
Current Company : Softwebsolution INC
User Group : Ahmedabad SQLServer UserGroup
Other : Microsoft Certified Technology Specialist (MCTS)

Comments and Discussions