在asp.net中长内容自动分页的实现-.NET教程2
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Page : System.Web.UI.Page
{
private string str;//字符15 private int strl;//字符总长度16 private int pagesize;//每页显示的字符数17 protected void Page_Load(object sender, EventArgs e)
{
// 在此处放置用户代码以初始化页面 20 str = "1234567891234567898522555";
pagesize = 3;
strl = str.Length;
Response.Write(strl);
substr();
}
private void substr()
{
int ct = Int32.Parse(Request.QueryString["page"]);
if (strl == (strl / pagesize) * pagesize)//看看页面的总记录是否能被每页的记录数整除31 {
for (int i = 1; i <= strl / pagesize; i++)
{
Response.Write("页:<a href="page.aspx?page=" mce_href="page.aspx?page="" + i + ">" + (i) + "</" + "a>");
}
string s = str.Substring(pagesize * ct - pagesize, pagesize);
Response.Write(s);
}
else if (ct * pagesize > strl)//在不被整除的情况下,最后一页的设置,如字符长13,每页3,则处理最后那一页的显示40
{
for (int i = 1; i <= (strl / pagesize) + 1; i++)
{
Response.Write("页:<a href="page.aspx?page=" mce_href="page.aspx?page="" + i + ">" + (i) + "</" + "a>");
}
string s = str.Substring((ct - 1) * pagesize, strl - (ct - 1) * pagesize);
Response.Write(s);
}
else //在不被整除的情况下其他页面的显示设置49 {
for (int i = 1; i <= strl / pagesize + 1; i++)
{
Response.Write("页:<a href="page.aspx?page=" mce_href="page.aspx?page="" + i + ">" + (i) + "</" + "a>");
}
string s = str.Substring(pagesize * ct - pagesize, pagesize); \
Response.Write(s);
}
}
}
:http://blog.csdn.net/duanxifeng888/archive/2010/08/22/5830468.aspx