/// <summary>
/// Linq分页
/// </summary>
int pagesize = ;//每页条数
int recordcount = ;//总条数
int pageindex = ;//当前第几页
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 = ; 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-)*pagesize).Take(pagesize);
rpt_Message.DataSource = data;
rpt_Message.DataBind();
}

aspx调用页码代码:

<%=sb.ToString() %>

Linq分页的更多相关文章

  1. Linq 分页不可缺少的两个方法

    //LINQ分页的方法 //1.获取总页数 public int GetPageCount(int pageSize)//pageSize是每页的行数 { //先查出总共有多少行 int rowCou ...

  2. C# SQL优化 及 Linq 分页

    每次写博客,第一句话都是这样的:程序员很苦逼,除了会写程序,还得会写博客!当然,希望将来的一天,某位老板看到此博客,给你的程序员职工加点薪资吧!因为程序员的世界除了苦逼就是沉默.我眼中的程序员大多都不 ...

  3. Linq分页查询

    //Linq分页查询 int pageIndex = Convert.ToInt32(HttpContext.Current.Request["PageIndex"]); int ...

  4. LINQ分页和排序,skip和Take 用法

    LINQ分页和排序,skip和Take 用法 dbconn.BidRecord.OrderBy(p=>p.bid_id).ToList<BidRecord>().OrderBy(p ...

  5. LINQ 分页 和存储过程分页

    存储过程分页 SELECT * FROM ( SELECT ROW_NUMBER() OVER(ORDER BY CreateDate DESC) AS RowNo, EstateAddress, E ...

  6. Linq分页排序通用方法

    1.通用方法 2.调用 -----------------------------1.------------------------------------------- public class ...

  7. linq分页组合查询

    一.linq高级查 1.模糊查(字符串包含) 1 public List<User> Select(string name) 2 { 3 return con.User.Where(r = ...

  8. MongoDB .Net Driver(C#驱动) - 内嵌数组/嵌入文档的操作(增加、删除、修改、查询(Linq 分页))

    目录 一.前言 1. 运行环境 二.前期准备工作 1. 创建 MongoDBContext MongoDb操作上下文类 2.创建测试类 3.创建测试代码 三.内嵌数组增加元素操作 1.Update.S ...

  9. LINQ分页工具

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Co ...

随机推荐

  1. 读书笔记-----Java并发编程实战(二)对象的共享

    public class NoVisibility{ private static boolean ready; private static int number; private static c ...

  2. 【CF】310 Div.1 C. Case of Chocolate

    线段树的简单题目,做一个离散化,O(lgn)可以找到id.RE了一晚上,额,后来找到了原因. /* 555C */ #include <iostream> #include <str ...

  3. 无法自动调试 未能调试远程过程。这通常说明未在服务器上启用调试 WCF 托管在IIS上

    解决方案,把新建的网站的app.config修改下配置 <system.web> <!-- 设置 compilation debug="true" 可将调试符号插 ...

  4. 【转】Xcode7.1环境下上架iOS App到AppStore 流程 -- 不错!!

    原文网址:http://www.jianshu.com/p/a8bd16be122f 1.官网地址 Apple Developer 地址:https://developer.apple.com/mem ...

  5. android左右晃动动画(红包左右晃动)

    TranslateAnimation animation = new TranslateAnimation(0, -5, 0, 0); animation.setInterpolator(new Ov ...

  6. 使用jenkins + python + selenium一步步搭建web自动化测试“框架”(1) - 各部件简介

    原先搭建过一个自动化测试框架,迷迷糊糊不求甚解,算是搭建了一个仅限于能用的.根本算不上框架的玩意儿. 现在回过头来好好看看究竟每一步是怎么联系起来的,是怎么运行起来的. 本次博客先说说各部件都是干什么 ...

  7. php中的variables_order

    PHP中的$_ENV是一个包含服务器端环境变量的数组.它是PHP中一个超级全局变量,我们可以在PHP 程序的任何地方直接访问它.     $_ENV只是被动的接受服务器端的环境变量并把它们转换为数组元 ...

  8. [LeetCode] Interleaving String 解题思路

    Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example,Given:s1 = ...

  9. __attribute__机制介绍 (转)

    1. __attribute__ GNU C的一大特色(却不被初学者所知)就是__attribute__机制. __attribute__可以设置函数属性(Function Attribute).变量 ...

  10. UILabel字体加粗等属性和特效

    /* Accessing the Text Attributes text  property font  property textColor  property textAlignment  pr ...