• 将DataTable进行分页并生成新的DataTable


     /////////////////
            /// <summary>
            /// 将DataTable进行分页并生成新的DataTable
            /// </summary>
            /// <param name=”dt”>原DataTable</param>
            /// <param name=”PageIndex”>需要的第n页</param>
            /// <param name=”PageSize”>每页页数</param>
            /// <returns>新的DataTable</returns>
            public DataTable GetPagedTable(DataTable dt, int PageIndex, int PageSize)
            {
                if (PageIndex == 0)
                {
                    return dt;
                }

                DataTable newdt = dt.Copy();

                newdt.Clear();

                //起始行数
                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;
            }

  • 相关阅读:
    查看PL/SQL编译时的错误信息
    Oracle字符集的查看查询和Oracle字符集的设置修改
    关于数字货币 韩国似乎在下一盘大棋
    上传图片如何对图片进行压缩canvas
    socket应用(vue、node.js、M站)
    web前端学习python之第一章_基础语法(二)
    从零开始 —— Canvas(一)
    前端必备之Node+mysql+ejs模版如何写接口
    浏览器缓存机制
    前端实现数组去重,如何高效快捷?
  • 原文地址:https://www.cnblogs.com/wuhuisheng/p/1985126.html
Copyright © 2020-2023  润新知