asp.Net長い文章は設定した行数でページを分けます

1831 ワード

 
  
public string OutputByLine(string strContent)//
{
int pageSize = int.Parse(ConfigurationManager.AppSettings["pageSize"]);// CONFIG
string lineBreak = ConfigurationManager.AppSettings["lineBreak"];// CONFIG
string lineBreakS = "";
string lineBreakE = "" +lineBreak+">";
strContent = strContent.Replace("\r
", "");
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("{0} |",i);
}
}
labPageNumber.Text = pageInfo;
for (int i = (currentPage-1)*pageSize; i < currentPage*pageSize&&i{
displayText += "
" + strLined[i] + "
";
}
return displayText;
}