t3.aspx
cs代码
public partial class t3 : System.Web.UI.Page
{
private string str;//字符
private int strl;//字符总长度
private int pagesize;//每页显示的字符数
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
str = "abcdefghijklmnopqrstu";
pagesize = 3;
strl = str.Length;
Response.Write(strl);
substr();
}
private void substr()
{
int ct = Int32.Parse(Request.QueryString["page"]);
if (strl == (strl / pagesize) * pagesize)//看看页面的总记录是否能被每页的记录数整除
{
for (int i = 1; i <= strl / pagesize; i++)
{
Response.Write("页:<a href=t3.aspx?page=" + i + ">" + (i) + "</" + "a>");
}
string s = str.Substring(pagesize * ct - pagesize, pagesize);
Response.Write(s);
}
else if (ct * pagesize > strl)//在不被整除的情况下,最后一页的设置,如字符长13,每页3,则处理最后那一页的显示
{
for (int i = 1; i <= (strl / pagesize) + 1; i++)
{
Response.Write("页:<a href=t3.aspx?page=" + i + ">" + (i) + "</" + "a>");
}
string s = str.Substring((ct - 1) * pagesize, strl - (ct - 1) * pagesize);
Response.Write(s);
}
else //在不被整除的情况下其他页面的显示设置
{
for (int i = 1; i <= strl / pagesize + 1; i++)
{
Response.Write("页:<a href=t3.aspx?page=" + i + ">" + (i) + "</" + "a>");
}
string s = str.Substring(pagesize * ct - pagesize, pagesize);
Response.Write(s);
}
}
}
{
private string str;//字符
private int strl;//字符总长度
private int pagesize;//每页显示的字符数
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
str = "abcdefghijklmnopqrstu";
pagesize = 3;
strl = str.Length;
Response.Write(strl);
substr();
}
private void substr()
{
int ct = Int32.Parse(Request.QueryString["page"]);
if (strl == (strl / pagesize) * pagesize)//看看页面的总记录是否能被每页的记录数整除
{
for (int i = 1; i <= strl / pagesize; i++)
{
Response.Write("页:<a href=t3.aspx?page=" + i + ">" + (i) + "</" + "a>");
}
string s = str.Substring(pagesize * ct - pagesize, pagesize);
Response.Write(s);
}
else if (ct * pagesize > strl)//在不被整除的情况下,最后一页的设置,如字符长13,每页3,则处理最后那一页的显示
{
for (int i = 1; i <= (strl / pagesize) + 1; i++)
{
Response.Write("页:<a href=t3.aspx?page=" + i + ">" + (i) + "</" + "a>");
}
string s = str.Substring((ct - 1) * pagesize, strl - (ct - 1) * pagesize);
Response.Write(s);
}
else //在不被整除的情况下其他页面的显示设置
{
for (int i = 1; i <= strl / pagesize + 1; i++)
{
Response.Write("页:<a href=t3.aspx?page=" + i + ">" + (i) + "</" + "a>");
}
string s = str.Substring(pagesize * ct - pagesize, pagesize);
Response.Write(s);
}
}
}
本文介绍了一个简单的ASP.NET分页实现案例,通过定义每页显示的字符数量,实现了字符串内容的基本分页浏览功能,并提供了页面导航链接。
7089

被折叠的 条评论
为什么被折叠?



