您现在的位置是:首页 >

文档怎么分页 ASP.NET分页链接方法

火烧 2022-08-01 21:55:47 1058
ASP.NET分页链接方法   /// lt ummary gt   /// 分页链接  /// lt / ummary gt   /// lt aram ame= ageSize gt lt / a

ASP.NET分页链接方法  

  /// <summary>

  /// 分页链接

  /// </summary>

  /// <param name= pageSize ></param>

  /// <param name= recordCount ></param>

  /// <param name= currentPage ></param>

  /// <param name= prev >当前页前面显示的数量</param>

  /// <param name= next >当前页后面显示的数量</param>

  /// <returns></returns>

  public string PageLink(int pageSize int recordCount int currentPage int prev int next)

  {

  int pageCount = recordCount % pageSize == ? (recordCount / pageSize) : ((int)Math Ceiling((double)recordCount / pageSize));

  StringBuilder sb = new StringBuilder();

  if (currentPage > && recordCount > )

  {

  sb Append( <a href= ?page= );

文档怎么分页 ASP.NET分页链接方法

  sb Append((currentPage ) ToString());

  sb Append( >前一页</a>&nbsp;&nbsp; );

  }

  if (currentPage > prev + )

  sb Append( <a href= ?page= > </a>&nbsp; &nbsp; );

  if (currentPage < prev)

  next = next + prev currentPage + ;

  if (next > pageCount currentPage)

  prev = prev + next (pageCount currentPage);

  for (int i = ; i <= pageCount; i++)

  {

  if (i == currentPage)

  {

  sb Append( <a href= ?page= + i + class= current ><font color= red > + i + </font></a>&nbsp;&nbsp; );

  }

  else

  {

  if (i > (currentPage prev ) && i < (currentPage + next + ))

  {

  sb Append( <a href= ?page= + i + > + i + </a>&nbsp;&nbsp; );

  }

  }

  }

  if (currentPage < pageCount next)

  sb Append( &nbsp;<a href= ?page= + pageCount ToString() + > + pageCount ToString() + </a> );

  if (currentPage < pageCount)

  sb Append( &nbsp;&nbsp;<a href= ?page= + (currentPage + ) ToString() + >后一页</a> );

  return sb ToString();

lishixinzhi/Article/program/net/201311/13867  
永远跟党走
  • 如果你觉得本站很棒,可以通过扫码支付打赏哦!

    • 微信收款码
    • 支付宝收款码