Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Repeater with Paging and Sorting Features

, 16 Jul 2009 CPOL
Repeater with Paging and Sorting features
ExtendedRepeater.zip
App_Code
ExtendedRepeater.suo
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)

Share

About the Author

bhadeliaimran
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)

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141223.1 | Last Updated 16 Jul 2009
Article Copyright 2009 by bhadeliaimran
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid