首页 > 其他 > 详细

Linq分页

时间:2014-07-07 00:54:09      阅读:328      评论:0      收藏:0      [点我收藏+]
        /// <summary>
        /// Linq分页
        /// </summary>
        int pagesize = 2;//每页条数
        int recordcount = 0;//总条数
        int pageindex = 1;//当前第几页
        public static string con = ConfigurationManager.ConnectionStrings["MySQLDBConnectionString"].ConnectionString;
        GuestBookDataContext ctx = new GuestBookDataContext(con);
        public StringBuilder sb = new StringBuilder();
        public void GetPage()
        {
            if (!String.IsNullOrEmpty(Request.QueryString["page"]))
            {
                pageindex = Convert.ToInt32(Request.QueryString["page"]);
            }
            recordcount = ctx.tbGuestBook.Count();
            int pagecount = (int)Math.Ceiling((decimal)recordcount/pagesize);//总页数
            sb.Append("共<font style=‘color:#FF0000‘>"+pageindex+"</font>/"+pagecount+"");
            for (int i = 1; i <= pagecount; i++)
            {
                sb.AppendFormat(@"<a href=‘?page={0}‘>{0}<a/>",i);
            }
            var data = (from gb in ctx.tbGuestBook orderby gb.PostTime descending select gb).Skip((pageindex-1)*pagesize).Take(pagesize);
            rpt_Message.DataSource = data;
            rpt_Message.DataBind();
        }

aspx调用页码代码:

<%=sb.ToString() %>

 

Linq分页,布布扣,bubuko.com

Linq分页

原文:http://www.cnblogs.com/liuswi/p/3822386.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!