龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > asp.net编程 >

ASP.NET实现长文章设定的行数分页源代码

时间:2009-12-21 11:47来源:未知 作者:admin 点击:
分享到:
下面是ASP.NET实现长文章设定的行数分页源代码 Code [http://www.xueit.com] 1 public string OutputByLine( string strContent) // 通过设定的行数分页 2 { 3 int pageSize = int .Parse(ConfigurationManager.AppSettings[ " pa

下面是ASP.NET实现长文章设定的行数分页源代码

Code [http://www.xueit.com]
 1 public string OutputByLine(string strContent)//通过设定的行数分页
 2     {
 3         int pageSize = int.Parse(ConfigurationManager.AppSettings["pageSize"]);//每页显示行数从CONFIG文件中取出
 4         string lineBreak = ConfigurationManager.AppSettings["lineBreak"];//换行符从CONFIG文件中取出
 5         string lineBreakS = "<"   lineBreak   ">";
 6         string lineBreakE = "</"  lineBreak ">";
 7         strContent = strContent.Replace("\r\n", "");
 8         string[] strLined = strContent.Split(new string[] {lineBreakS, lineBreakE }, StringSplitOptions.RemoveEmptyEntries);//以DIV为换行符
 9         int pageCount = strLined.Length / pageSize;
10         int pageCountPlus = strLined.Length % pageSize == 0 ? 0 : 1;//非满页
11         pageCount = pageCount   pageCountPlus;//总页数
12         int currentPage = 1;//当前页码
13         string displayText = null;
14         if (Request.QueryString["pageIndex"]!=null) //获取翻页页码
15         {
16             currentPage = Convert.ToInt32(Request.QueryString["pageIndex"].ToString());
17         }
18         string pageInfo = "";//页数信息
19         for (int i = 1; i < pageCount 1; i  )
20         {
21             
22             if (i==currentPage)
23             {
24                 pageInfo  = ""   i   "";
25                 if (pageCount>1)
26                 {
27                     pageInfo  = " | ";
28                 }
29             }
30             else
31             {
32                 pageInfo  = string.Format("<a href='newshow.aspx?pageIndex={0}' title='翻到第{0}页'>{0} | </a>",i);
33             }
34         }
35         labPageNumber.Text = pageInfo;
36         for (int i = (currentPage-1)*pageSize; i < currentPage*pageSize&&i<strLined.Length; i  )
37         {
38             displayText  = "<div>"   strLined[i]   "</div>";
39         }
40         return displayText;
41     }
精彩图集

赞助商链接