文章分页浏览

在类似文章内容的页面中,当内容过于多的情况下,如果一直往下拉着看,很容易让用户感到疲劳,效果不好,所以需要分页显示出来,大致的思路看一下的例子:

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page
{
    private string wz = "aabbccdde";
    private string diswz=null;
    private int pageCount = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            if (Request["id"] != null)
            {
             
                int id = Convert.ToInt32(Request["id"].ToString());
                if (id != 5)
                {
                    diswz = wz.Substring((id - 1) * 2, 2);
                }
                else
                {
                    diswz = wz.Substring((id - 1) * 2);
                }
                this.Label1.Text = diswz;
            }
            else
            {
                diswz = wz.Substring(0,2);
                this.Label1.Text = diswz;
            }
            disLabel2(wz);
        }
    }
    public void disLabel2(string str)
    {
        int strCount = str.Length;
        //比如每页显示2个字符
        pageCount = ((strCount - 1) / 2) + 1;
        for (int i = 0; i < pageCount; i++)
        {
            this.Label2.Text += "<a href='?id="+(i+1)+"'>["+(i + 1)+"]</a>";
        }
    }
}

上面只是做个小小的测试,具体实施的时候我们有很多问题要考虑,下面的文件是分页的示例,可以下载下来看一下..

 /Files/shuang121/DevPagerSample.rar

多思考,多创新,才是正道!
原文地址:https://www.cnblogs.com/shuang121/p/1970098.html