asp.net中利用Jquery+Ajax+Json实现无刷新分页的实例代(4)

#region 模拟数据
    private static DataTable CreateDT()
    {
        DataTable dt = new DataTable();
        dt.Columns.Add(new DataColumn("Id", typeof(int)) { DefaultValue = 0 });
        dt.Columns.Add(new DataColumn("Name", typeof(string)) { DefaultValue = "1" });
        dt.Columns.Add(new DataColumn("Sex", typeof(string)) { DefaultValue = "男" });
        for (int i = 1; i <= 1000; i++)
        {
            dt.Rows.Add(i, "张三" + i.ToString().PadLeft(4, '0'));
        }
        RecordCount = dt.Rows.Count;
        return dt;
    }
    #endregion

/// <summary> 
    /// 对DataTable进行分页,起始页为1 
    /// </summary> 
    /// <param></param> 
    /// <param></param> 
    /// <param></param> 
    /// <returns></returns> 
    public static 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; 
        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; 
    } 

    /// <summary> 
    /// 获取总页数 
    /// </summary> 
    /// <param>结果集数量</param> 
    /// <param>页面数量</param> 
    /// <returns></returns> 
    public static int getPageCount(int sumCount, int pageSize) 
    { 
        int page = sumCount / pageSize; 
        if (sumCount % pageSize > 0) 
        { 
            page = page + 1; 
        } 
        return page; 
    } 
 

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjzsgs.html