復制代碼 代碼如下:
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;
}