segunda-feira, 20 de julho de 2015

PagingDataTable

using System.Data;
using System.Linq;
using System.Web.UI.WebControls;

namespace Lapuinka.Utils
{
    public static class PagingDataTable
    {
        public static DataTable Paging(DataTable dt, int rowStart, int rowFinish)
        {
            var rows = (from row in dt.AsEnumerable()
                        select row).ToList().Skip(rowStart).Take(rowFinish);

            var dtPaged = dt.Clone();

            foreach (var dataRow in rows)
            {
                dtPaged.ImportRow(dataRow);
            }

            return dtPaged;
        }

        public static string GetSortDirection(SortDirection sortDirection)
        {
            if (sortDirection == SortDirection.Ascending)
                return "ASC";
            else
                return "DESC";
        }
    }
}


Postar um comentário