菜鸟求解分页知识

baidu_29583265 2015-08-10 06:15:22
public static Pager<T> ExecutePager<T>(string sqlTable, string sqlColumns, string sqlWhere, string sqlSort, int pageIndex, int pageSize) where T : new() {



}自学菜鸟求详细解悉此方法public static Pager<T> ExecutePager<T>()
...全文
151 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
smthgdin_020 2015-08-11
  • 打赏
  • 举报
回复
public static Pager<T> ExecutePager<T>(string sqlTable, string sqlColumns, string sqlWhere, string sqlSort, int pageIndex, int pageSize) where T : new() 一个静态方法,而且是泛型方法。 参数意义推测: sqlTable:表名 sqlColumns:多个列名 sqlWhere:查询条件 sqlSort:排序 pageIndex:当前页索引 pageSize:每页的行数 泛型约束:类型参数t必须有个无参数的构造函数 返回值:一个泛型类 具体你看例子。
宝_爸 2015-08-11
  • 打赏
  • 举报
回复
刚才还看到webdiyer发布了一个分页控件MvcPager 3.0版

http://bbs.csdn.net/topics/391051120
yaotomo 2015-08-11
  • 打赏
  • 举报
回复
利用SQL语句或存储过程分页,需要传递的参数:当前页索引,每页显示多少条数据
devmiao 2015-08-10
  • 打赏
  • 举报
回复
就是一个泛型方法,index是页码 size是页数据量,前面是查询条件
风云再起9310 2015-08-10
  • 打赏
  • 举报
回复
项目的一个分页类,你可以参考一下,写了这样的一个类,分页问题都是引用就行了,希望可以帮到你:
  public class PagedList<T> : List<T>
    {
        /// <summary>
        /// 分页编号
        /// </summary>
        public int intPageIndex { get; set; }

        /// <summary>
        /// 分页大小
        /// </summary>
        public int intPageSize { get; set; }

        /// <summary>
        /// 分页数
        /// </summary>
        public int intPages { get; set; }

        /// <summary>
        /// 总元素的个数
        /// </summary>
        public int intTotalCount { get; set; }


        /// <summary>
        /// 是否有下一页
        /// </summary>
        public bool HasNextPage { get; set; }

        /// <summary>
        /// 是否有上一页
        /// </summary>
        public bool HasPrPage { get; set; }

        public PagedList(IQueryable<T> list, int intPageIndex, int intPageSize, int intPageCount)
        {
            intTotalCount = intPageCount;

            if (intTotalCount % intPageSize == 0 && intTotalCount != 0) intPages = intTotalCount / intPageSize;
            else intPages = intTotalCount / intPageSize + 1;

            if (intPageIndex >= intPages) intPageIndex = intPages;

            this.intPageIndex = intPageIndex;
            this.intPageSize = intPageSize;

            //var pageResult = list.Skip((intPageIndex - 1) * intPageSize).Take(intPageSize).ToList<T>();

            //intCount = list.Count();

            HasNextPage = this.intPageIndex < this.intPages ? true : false;
            HasPrPage = this.intPageIndex > 1 ? true : false;
            if (list!=null)
            {
                foreach (var t in list.ToList<T>())
                {
                    this.Add(t);
                }
            }
            
        }
        public PagedList(List<T> list, int intPageIndex, int intPageSize, int intPageCount)
        {
            intTotalCount = intPageCount;

            if (intTotalCount % intPageSize == 0 && intTotalCount != 0) intPages = intTotalCount / intPageSize;
            else intPages = intTotalCount / intPageSize + 1;

            if (intPageIndex >= intPages) intPageIndex = intPages;

            this.intPageIndex = intPageIndex;
            this.intPageSize = intPageSize;

            //var pageResult = list.Skip((intPageIndex - 1) * intPageSize).Take(intPageSize).ToList<T>();

            //intCount = list.Count();

            HasNextPage = this.intPageIndex < this.intPages ? true : false;
            HasPrPage = this.intPageIndex > 1 ? true : false;
            if (list != null)
            {
                foreach (var t in list.ToList<T>())
                {
                    this.Add(t);
                }
            }

        }
        public PagedList(IEnumerable<T> list, int intPageIndex, int intPageSize, int intPageCount)
            : this(list as IQueryable<T>, intPageIndex, intPageSize, intPageCount)
        {
        }





        /// <summary>
        /// 下一页URL 自带搜索参数
        /// </summary>
        public string NextPageURL
        {
            get
            {
                string nextPageURL = RequestHelper.RawUrl;

                int nextPage = this.intPageIndex + 1;

                if (nextPage > this.intPages) return "javascript:;";

                if (nextPageURL.ToLower().IndexOf("&page=") > -1)
                {
                    nextPageURL = nextPageURL.Substring(0, nextPageURL.ToLower().IndexOf("&page=")) + "&page=";
                }
                else if (nextPageURL.ToLower().IndexOf("?page=") > -1)
                {
                    nextPageURL = nextPageURL.Substring(0, nextPageURL.ToLower().IndexOf("?page=")) + "?page=";
                }
                else if (nextPageURL.ToLower().IndexOf("?") > -1)
                {
                    if (nextPageURL.EndsWith("?"))
                        nextPageURL += "Page=";
                    else
                        nextPageURL += "&Page=";
                }
                else
                {
                    nextPageURL += "?page=";
                }
                return nextPageURL + nextPage.ToString();
            }
        }


        /// <summary>
        /// 上一页URL 自带搜索参数
        /// </summary>
        public string PrevPageURL
        {
            get
            {
                string prevPageURL = RequestHelper.RawUrl;

                int prevPage = this.intPageIndex - 1;

                if (prevPage <= 0) return "javascript:;";

                if (prevPageURL.ToLower().IndexOf("&page=") > -1)
                {
                    prevPageURL = prevPageURL.Substring(0, prevPageURL.ToLower().IndexOf("&page=")) + "&page=";
                }
                else if (prevPageURL.ToLower().IndexOf("?page=") > -1)
                {
                    prevPageURL = prevPageURL.Substring(0, prevPageURL.ToLower().IndexOf("?page=")) + "?page=";
                }
                else if (prevPageURL.ToLower().IndexOf("?") > -1)
                {
                    if (prevPageURL.EndsWith("?"))
                        prevPageURL += "Page=";
                    else
                        prevPageURL += "&Page=";
                }
                else
                {
                    prevPageURL += "?page=";
                }
                return prevPageURL + prevPage.ToString();
            }
        }
    }
全栈极简 2015-08-10
  • 打赏
  • 举报
回复
这有分页代码示例,不过基于oracle数据库。 http://blog.csdn.net/chinacsharper/article/details/9095387
  • 打赏
  • 举报
回复
空方法你求解个啥呢?

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧