3

I am doing paging in a Listview with Entity Framework and I'm stuck when passing startindex and maxrows after clicking the next/prev button

This is my code

private  List<WorkItem> Data(int startindex, int maxrows)
{            
       return (from x in ss.WorkItem
                    select x).OrderBy(p => p.WorkItemID).Skip(startindex).Take(maxrows).ToList();

}

protected void lvWorkItems_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
{
        this.DataPager1.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
        lvWorkItems.DataSource = Data(e.StartRowIndex,e.MaximumRows);

        lvWorkItems.DataBind();
}

My problem is how to pass startindex and maxrows when I click on next/Previous button. Please help

4

2 に答える 2

1

これはまさに私の問題でもありました。

しかし、私の問題は、ビジネス出力クラス メソッドの構造を変更することで解決されました。

もちろん、この方法では、データ出力と行数が必要です。

また、同じページ レイアウト データをデータベースから取得する必要があることに関連する問題を忘れないでください。

私のクラスは、次のことを行うように設計されました。

using System.Collections.Generic;

using System.Linq;

using Andish.CSS.Common.Enum;

using AutoMapper;

using system.linq.dynamic;


namespace Andish.CSS.Common.Result.Implementation

{

   public static class PagingResult

    {

        public static PageResult<K> ToPageResult<T, K>(this IQueryable<T> queryable, int rowCount,
            int pageNumber, string sortField, DynamicLinqSortFieldKind 

dynamicLinqSortFieldKind)

        {

var allQueryRow = queryable.ToList<T>().Count();

            var skipLen = (pageNumber - 1) * rowCount;


            string orderKind = "";

            orderKind = dynamicLinqSortFieldKind == DynamicLinqSortFieldKind.Ascending ? " Asc" : " Desc";

 PageResult<K> pageResult = new PageResult<K>

                                           {

                                               PageNumber = pageNumber,

                                               RowCount = rowCount,

                                               Result = Mapper.Map<IList<K>>(queryable.OrderBy(sortField + orderKind)
                                                                             .Skip(skipLen).Take(rowCount).ToList<T>()),
                                               ResultRowCount = allQueryRow,

                                               PageCount = allQueryRow % rowCount == 0 ? allQueryRow / rowCount : (allQueryRow / rowCount) + 1

                                           };

            return pageResult;


        }

 }



}

create this enum

public enum DynamicLinqSortFieldKind

    {

        Ascending = 0,

        Descending = 1

    }

そして、この拡張メソッドを使用するには、このようにします。クラス ExecutiveUnit からの結果が 1 つあり、このクラスを別のクラス ExecutiveUnitModel にマップします。私はautomapper nugetを使用しています。

var xresult = result.ToPageResult<ExecutiveUnit, ExecutiveUnitModel>(RowNumbers, pageNumber, "Code", DynamicLinqSortFieldKind.Ascending);
于 2013-03-12T07:25:28.127 に答える