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
Check it out please , it extension method :
public static IQueryable<T> MyPage<T, TResult>(this IQueryable<T> obj, int
page, int pageSize, System.Linq.Expressions.Expression<Func<T, TResult>>
keySelector, bool asc, out int rowsCount)
{
rowsCount = obj.Count();
if (asc)
{
return obj.OrderBy(keySelector).Skip(page * pageSize).Take(pageSize);
}
else
{
return obj.OrderByDescending(keySelector).Skip(page * pageSize).Take(pageSize);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With