C# datatable分页函数和 list 分页

public DataTable GetPagedTable(DataTable dt, int PageIndex, int PageSize, out int recound)

        {

            if (dt == null || dt.Rows == null || dt.Rows.Count <= 0)

            {

                recound = 0;

                return null;

            }

            if (PageIndex < 1)

            {

                PageIndex = 1;

            }

     else if (PageIndex > 1 || PageIndex == 1)

            {

                PageIndex = PageIndex + 1;

            }

            DataTable newdt = dt.Copy();

            newdt.Clear();

            recound = dt.Rows.Count;

            int rowbegin = (PageIndex - 1) * PageSize;

            //停止行数

            int rowend = PageIndex * PageSize;

            if (rowbegin >= dt.Rows.Count)

            {

                return newdt;

            }

            if (rowend > dt.Rows.Count)

            {

                rowend = dt.Rows.Count;

            }

            //生成新的DataTable

            for (int i = rowbegin; i <= rowend - 1; i++)

            {

                DataRow newdr = newdt.NewRow();

                DataRow dr = dt.Rows[i];

                foreach (DataColumn column in dt.Columns)

                {

                    newdr[column.ColumnName] = dr[column.ColumnName];

                }

                newdt.Rows.Add(newdr);

            }

            return newdt;

        }
take-skip分页 针对集合 mapList.List = mapList.List.Skip((oldpageIndex – 1) * oldpageSize).Take(oldpageSize).ToList();
 附加://模糊查询添加回车即查询   $(“#txtKeywords”).bind(“keyup”, function (e) {

if (e.keyCode == 13) {

gv.reload();

}

})

来源地址:C# datatable分页函数和 list 分页

转载声明:本站文章若无特别说明,皆为原创,转载请注明来源:www.88531.cn资享网,谢谢!^^

© 版权声明
THE END
喜欢就支持一下吧
点赞23 分享