[代码][C#]代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/// <summary>
/// 分页内容
/// </summary>
/// <param name="size">页面大小</param>
/// <param name="count">页面数量</param>
/// <param name="currendIndex">当前页</param>
/// <param name="pattern">url模式:demo.aspx?page={0}</param>
/// <param name="target">窗口模式</param>
/// <returns></returns>
public static string get_pagenation(int size,
                                    int count,
                                    int currendIndex,
                                    string pattern,
                                    string target)
{
    //1>打开窗口目标
    target = string.IsNullOrEmpty(target) ? "_top" : target;
    //2>总页数
    int pageCount = count / size;
    pageCount = pageCount * size == count ? pageCount : pageCount + 1;
    //3>分页内容
    StringBuilder strHtml = new StringBuilder();
    strHtml.Append("<span class='pagenation'>");
 
    #region 首部处理
    if (currendIndex > 1)
    {
        strHtml.AppendFormat("<a href='1' target='{0}'>[首页]</a>", target);
        strHtml.AppendFormat("<a href='{0}' target='{1}'>[上一页]</a>", string.Format(pattern, currendIndex - 1), target);
    }
    else
    {
        strHtml.Append("<span class='disabled'>[首页]</span>&nbsp;&nbsp;<span class='disabled'>[上一页]</span>");
    }
    #endregion
 
    #region 中间部分
    int i = 1;
 
    int right = (currendIndex + 4) > pageCount ? pageCount : currendIndex + 4;
    if (currendIndex > 6)
    {
        i = currendIndex - 5;
    }
    else
    {
        right = pageCount >= 10 ? 10 : pageCount;
    }
    for (; i <= right; i++)
    {
        if (i == currendIndex)
        {
            strHtml.AppendFormat("<font class='current'>{0}</font>", i);
            strHtml.AppendLine();
            continue;
        }
        strHtml.AppendFormat("<a href='{0}' target='{1}'>[{2}]</a>", string.Format(pattern, i), target, i);
        strHtml.AppendLine();
    }
    #endregion
 
    #region 尾部处理
    if (currendIndex == pageCount)
    {
        strHtml.Append("<span class='disabled'>[下一页]</span><span class='disabled'>[末页]</span>");
        strHtml.AppendFormat("总共({0})页", pageCount);
    }
    else
    {
        strHtml.AppendFormat("<a href='{0}' target='{1}'>[下一页]</a>", string.Format(pattern, currendIndex + 1), target);
        strHtml.AppendFormat("<a href='{0}' target='{1}'>[末页]</a>", string.Format(pattern, pageCount), target);
        strHtml.AppendFormat("&nbsp;&nbsp;<label>总共({0})页</label>", pageCount);
    }
    #endregion
 
    strHtml.Append("</span>");
 
    return strHtml.ToString();
}

ASP.NET分页的更多相关文章

  1. asp.net分页控件

    一.说明 AspNetPager.dll这个分页控件主要用于asp.net webform网站,现将整理代码如下 二.代码 1.首先在测试页面Default.aspx页面添加引用 <%@ Reg ...

  2. asp.net 分页-自己写分页控件

    去年就发表过asp.net 分页-利用后台直接生成html分页 ,那种方法只是单纯的实现了分页,基本不能使用,那时就想写个自己的分页控件,无奈能力有限.最近有点时间了,就自己做出了这个分页控件.我承认 ...

  3. (转)asp.net分页存储过程

    Asp.Net分页存储过程 SQL分页语句 一.比较万能的分页: sql代码: 1 2 3 select top 每页显示的记录数 * from topic where id not in  (sel ...

  4. 《ASP.NET1200例》<asp:DataList>分页显示图片

    aspx页面代码 <asp:DataList ID="dlPhoto" runat="server" Height="137px" W ...

  5. ASP.NET分页存储过程,解决搜索时丢失条件信息

    存储过程: -- ============================================= -- Author: -- Create date: -- Description: 分页 ...

  6. 【asp.net爬虫】asp.NET分页控件抓取第n页数据 javascript:__doPostBack

    最近在模拟HTTP请求抓取数据,但是服务器是asp.net开发的 分页控件代码 <tr> <td align="left">共&nbsp210&am ...

  7. ASP.NET - 分页

    效果: SQL-存储过程(Paging): ROW_NUMBER() over(order by MessageDateTime desc)  其中的 MessageDateTime desc 代表的 ...

  8. ASP.NET分页正品—分页真

     承接上篇博文<ASP.NET真假分页-假分页>:http://blog.csdn.net/u010773667/article/details/38845009,继续解说ASP.NE ...

  9. ASP.NET 分页+组合查询 练习

    分页和组合查询都是通过拼接SQL语句到数据库查询进行实现 到汽车表(car)中查询 ,汽车表选取了“编号 code”,“车名 name”,“日期 time”,“油耗 oil ”,“马力 powers” ...

  10. asp.net分页之AJAX 分页

    查询功能是开发中最重要的一个功能,大量数据的显示,我们用的最多的就是分页. 在ASP.NET 中有很多数据展现的控件,比如Repeater.GridView,用的最多的GridView,它同时也自带了 ...

随机推荐

  1. 旅行计划-DAG上最长路

    http://www.luogu.org/problem/show?pid=1137 题目描述 小明要去一个国家旅游.这个国家有N个城市,编号为1-N,并且有M条道路连接着,小明准备从其中一个城市出发 ...

  2. HTTP Status 500 - javax.servlet.ServletException

    运行某个jsp页面时提示 type Exception report message javax.servlet.ServletException: java.lang.NoClassDefFound ...

  3. ASP.NET的SEO:使用.ashx文件——排除重复内容

    本系列目录 不同的链接指向的页面如果具有大量相同的内容,这种现象就会被称为"重复内容",如果一个网站的重复内容很多,搜索引擎就会认为这个网站的价值不高.所以我们应尽量避免各种重复内 ...

  4. Linux内核中ioremap映射的透彻理解

    几乎每一种外设都是通过读写设备上的寄存器来进行的,通常包括控制寄存器.状态寄存器和数据寄存器三大类,外设的寄存器通常被连续地编址.根据CPU体系结构的不同,CPU对IO端口的编址方式有两种: (1)I ...

  5. 【Qt】使用QProcess调用其它程序或脚本

    大概试了一下,还是不错的,不过字符编码问题还不太好解决: 代码: #include "mainwindow.h" #include "ui_mainwindow.h&qu ...

  6. new_things

    'NapCat' in AppStore for reading codes from github. and the ----minibufexpl                |  + nerd ...

  7. 创建parameter id

    Custom Parameter-id Creation By Abhijit Daptary, Capgemini India Step1: Creation of parameter ID.  P ...

  8. ADO.NET数据库

    ASP.NET提供了ADO.NET技术,它是ASP.NET应用程序与数据库进行交互的一种技术. ADO.NET技术把对数据库的操作分为几个步骤,并为每个步骤提供对象来封装操作过程,从而使对数据库的操作 ...

  9. foreach 和 list.foreach 初步测试

    单纯从速度上讲 小数据量下foreach 较快,list.Foreach 由于 public void ForEach(Action<T> action) { ; i <this._ ...

  10. Winform TreeView 单选

    private void treeView1_AfterCheck(object sender, TreeViewEventArgs e) { //通过鼠标或者键盘触发事件,防止修改节点的Checke ...