asp.net分页

1,直接通过sql语句分页

            int Skip = (PageIndex - 1) * PageSize;
            int Take = PageSize;
            string strIsDesc = IsDesc ? "desc" : "asc";
            StringBuilder sb = new StringBuilder();
            sb.Append("with temp as (select top " + (Skip + Take));
            sb.Append(" ROW_NUMBER() OVER(ORDER BY " + OrderField + " " + strIsDesc);
            sb.Append(") AS RowID, * from cfljl ");
            sb.Append("  where " + Condition + ") select * from temp ");
            sb.Append(" where RowID>" + Skip);

2,通过linq在 实体 模型中获取分页数据

        public List<VIEW_ZCTZ> GetListJD_ZCTZ(JD_ZCTZ zctz, int? intPageIndex, int? intPageSize, string strOrderField, bool isDesc)
        {

            StringBuilder strESql = new StringBuilder(" it.LSH>0");
            List<ObjectParameter> paras = new List<ObjectParameter>();
            if (zctz.kpbh!=null&zctz.kpbh!=0)
            {
                strESql.Append(" and  it.kpbh = @kpbh ");
                var param = new ObjectParameter("kpbh", zctz.kpbh);
                paras.Add(param);
            }
            strESql.Append(" order by it.kpbh " + (isDesc ? "desc" : "asc") + ",it.kpbh ");
            if (intPageIndex != null)
                strESql.Append(" SKIP " + (((int)intPageIndex - 1) * (int)intPageSize) + " LIMIT " + ((int)intPageSize));
            return Context.VIEW_ZCTZ.Where(strESql.ToString(), paras.ToArray()).ToList();
        }

posted @ 2013-07-09 11:24  namehwh  阅读(184)  评论(0编辑  收藏  举报