当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > asp.net 长文章通过设定的行数分页

ASP.NET
VS 2008和.NET 3.5 Beta2新特性介绍
VS 2008和.NET 3.5 Beta2常见问题的解决方案
Asp.net 备份和还原SQL Server及压缩Access数据库
Asp.Net中动态页面转静态页面
ASP.NET缓存:方法分析和实践示例
ASP.NET Forms验证(自定义、角色提供程序)
ASP.NET 2.0当中的Call Back机制
ASP.NET中MD5和SHA1加密的几种方法
在ASP.NET Atlas中调用Web Service
Cast的妙用:泛用LINQ 語句
ASP.NET将物件序列化成Binary储存至DB or File
使用Ajax后,原来导出功能失败的解决方法
装箱、转型、方法调用他们究竟有什么区别?
ASP.NET MVC :实现我们自己的视图引擎
如何构造一个C#语言的爬虫程序
Asp.net Mvc Framework可以在Controller中使用的Url.Action方法
校内网API的.net版本XiaoNei.Net 1.0(非官方)
使用ExtJS GridPanel从Web Service 获取、绑定和显示数据
从UI->DB一条龙到代码生成到EOS,谈谈快速开发
ASP.Net安装简明手册

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-10   浏览: 70 ::
收藏到网摘: n/a

长文章通过设定的行数来实现分页的代码。
复制代码 代码如下:

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 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;
}