码迷,mamicode.com
首页 > 其他好文 > 详细

Linq分页

时间:2014-07-07 00:54:29      阅读:262      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   color   os   cti   

        /// <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分页

标签:des   style   blog   color   os   cti   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!