asp.net 长文章通过设定的行数分页

泥土的味道是苦涩的,海水的味道是苦咸的,树林中清新的空气也有着一丝苦津津的味道。这苦的大自然,孕育了人们交织着各种苦痛的心灵。广袤的土地,浩瀚的海洋,辽阔的天空,构成了我们这个世界。

public string OutputByLine(string strContent)//通过设定的行数分页
{
int pageSize = int.Parse(ConfigurationManager.AppSettings["pageSize"]);//每页显示行数从CONFIG文件中取出
string lineBreak = ConfigurationManager.AppSettings["lineBreak"];//换行符从CONFIG文件中取出
string lineBreakS = "<" + lineBreak + ">";
string lineBreakE = "</" +lineBreak+">";
strContent = strContent.Replace("\r\n", "");
string[] strLined = strContent.Split(new string[] {lineBreakS, lineBreakE }, StringSplitOptions.RemoveEmptyEntries);//以DIV为换行符
int pageCount = strLined.Length / pageSize;
int pageCountPlus = strLined.Length % pageSize == 0 ? 0 : 1;//非满页
pageCount = pageCount + pageCountPlus;//总页数
int currentPage = 1;//当前页码
string displayText = null;
if (Request.QueryString["pageIndex"]!=null) //获取翻页页码
{
currentPage = Convert.ToInt32(Request.QueryString["pageIndex"].ToString());
}
string pageInfo = "";//页数信息
for (int i = 1; i < pageCount+1; i++)
{ if (i==currentPage)
{
pageInfo += " 第" + i + "页";
if (pageCount>1)
{
pageInfo += " | ";
}
}
else
{
pageInfo += string.Format("<a rel="nofollow noopener noreferrer" href='newshow.aspx?pageIndex={0}' title="翻到第{0}页">{0} | </a>",i);
}
}
labPageNumber.Text = pageInfo;
for (int i = (currentPage-1)*pageSize; i < currentPage*pageSize&&i<strLined.Length; i++)
{
displayText += "<div>" + strLined[i] + "</div>";
}
return displayText;
}

到此这篇关于asp.net 长文章通过设定的行数分页就介绍到这了。对牛弹琴伤心的不是牛,先了解对象后,再“弹琴”。更多相关asp.net 长文章通过设定的行数分页内容请查看相关栏目,小编编辑不易,再次感谢大家的支持!

您可能有感兴趣的文章
ASP.NET中Response.BufferOutput属性的使用技巧

ASP.NET轻量级MVC框架Nancy的基本用法

使用grpcui测试ASP.NET core的gRPC服务

ASP.NET Core中的对象池介绍

.NET集成ORM框架HiSql