Realize paging display of overly long text content

   In the process of making our website, we will inevitably encounter the problem that the text content of the final display page is too long, which will cause the viewer to keep flipping the screen, so is there any way to paginate the text content that is too long?

Display content section:
code  code
//FLYWE Blog
//www.flywe.net
//Define variables
int i,start,stop,t,stat,statt,pp,pagecount,pagesize;
//variable initial value
stat=0;
statt=0;
start=0 ;//The string position to start the query, the initial value is 0
stop=0;
pagesize=2000;//Define at least the number of strings displayed on each page
pagecount=0;

//Get the current number of pages
pa=Request.Params["page "];
if(pa=="" || pa==null)
pa="1";
pp=Convert.ToInt32(pa);

//Get the content
articletxt=rs["contenttxt"].ToString();

/ /Determine whether the content length of the page is greater than the defined number of strings displayed on each page at least
if(articletxt.Length>=pagesize)//If it is greater than the number of strings, we can display it in pagination
{
t=articletxt.Length/pagesize;// Get the approximate total number of pages
//loop based on the number of pages currently acquired
for(i=0;i<t;i++)
{
  //If the range from the query start position to the query exceeds the length of the entire content, then you don't need to look for breakpoints (paging points); otherwise, look for
  if(start+pagesize<articletxt .Length)
  {
   stat=articletxt.IndexOf("</P>",start+pagesize);//Find the position of the </P> paging point
   if(stat<=0)//If you can't find
    stat=articletxt. IndexOf("</p>",start+pagesize);//Find</p> the position of the paging point; here you can set the judgment of the paging point by yourself
  }
  if(stat<=0)//If no paging is found point, it means that paging cannot be done, so there is no need to do other work; otherwise, paging is performed
   articletext=articletxt;//The result is paid to the variable to be exported
  else
  {
   stop=stat;//The position of the paging point is also used as The end position of this page
   if(start+pagesize>=articletxt.Length)//If the range from the start position to the query exceeds the length of the entire content, then the end position of this page is the end of the content
    stop=articletxt.Length;
   if(pp==i+1)//If it is current, then output the content of the current page
    articletext=articletxt.Substring(start,stop-start);//Get the start position of the content to the end position of this string output
   start=stat;//The end position is used as the start position of the next page
   pagecount++;// get the actual total number of pages
  }
}
}


Pagination section:
code  code
string html;//Define the paging code variable
if(pagecount>1)//When the number of pages is greater than 1, we display the number of pages
{
  for(i=1;i<=pagecount;i++)
  {
     if(i==pp) //If it is the current page, bold display
      html+="<b>["+i+"]</b> ";
     else
    html+="<a href=?id="+articleid+"&page="+i+"> ["+i+"]</a> ";
  }
  if(pp+1>pagecount)//Display the next page for easy browsing
   html+="<a href=?id="+articleid+"&page="+(pagecount )+">[Next Page]</a></p>";
  else
   html+="<a href=?id="+articleid+"&page="+(pp+1)+">[Next Page ]</a></p>";
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324830551&siteId=291194637