複製代碼 代碼如下: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;
}