熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

ASP.NET分頁鏈接方法

2022-06-13   來源: .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)MathCeiling((double)recordCount / pageSize));

  StringBuilder sb = new StringBuilder();

  if (currentPage > && recordCount > )

  {

  sbAppend(<a href=\?page=);

  sbAppend((currentPage )ToString());

  sbAppend(\>前一頁</a>&nbsp;&nbsp;);

  }

  if (currentPage > prev + )

  sbAppend(<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)

  {

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

  }

  else

  {

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

  {

  sbAppend(<a href=\?page= + i + \> + i + </a>&nbsp;&nbsp;);

  }

  }

  }

  if (currentPage < pageCount next)

  sbAppend(&nbsp;<a href=\?page= + pageCountToString() + \> + pageCountToString() + </a>);

  if (currentPage < pageCount)

  sbAppend(&nbsp;&nbsp;<a href=\?page= + (currentPage + )ToString() + \>後一頁</a>);

  return sbToString();

  }


From:http://tw.wingwit.com/Article/program/net/201311/13867.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.