WinForm DataGridView以List为数据源,实现分页查询功能

public override List<ModelParent> GetList(int pageIndex, int pageLength, string keyword, int id, ref int DataCount)
{
DataList = Code.BLLInterface.GetList(new Model_ProgramRequest(), FilePath, new Model_ProgramRequest().ClassName);
DataCount = DataList.Count;
List<ModelParent> result = new List<ModelParent>();
List<Model_ProgramRequest> list = DataList.FindAll(x => x.ProgramNo.Contains(keyword) && x.Status != 3);
list.Sort((a,b)=>a.RequestID.CompareTo(b.RequestID));

//通过list的Skip方法和Take方法进行分页查询。 pageIndex:第几页,pageLength:每页长度
var skip = (pageIndex - 1) * pageLength;
foreach (Model_ProgramRequest ProgramRequest in list.Skip(skip).Take(pageLength))
{
result.Add(ProgramRequest);
}
return result;
}

上一篇:优选list的几种去重方式


下一篇:Django-admin 管理工具