Article paging Methods

Source: Internet
Author: User

Method 1 of pagination function: pagination based on the number of words on each page

Public class articlepagebase
{
Public static httprequest request;
Public static string page;
Public articlepagebase ()
{

}

// The request here is submitted on the previous page

Public static string outputbysize (string p_strcontent, httprequest request, int ID) // paging Function
{
String m_strret = "";
Int m_intpagesize = 100; // size of each page of the document
Int m_intcurrentpage = 1; // set the first page to the initial Page.
Int m_inttotalpage = 0;
Int m_intarticlelength = p_strcontent.length; // Article Length
If (m_intpagesize <m_intarticlelength)
{// If the size of each page is greater than the length of the article, no paging is required.
If (m_intarticlelength % m_intpagesize = 0)
{// Set total pages count
M_inttotalpage = m_intarticlelength/m_intpagesize;
}
Else
{// If the totalsize
M_inttotalpage = m_intarticlelength/m_intpagesize + 1;
}
If (request. querystring ["Ps"]! = NULL)
{// Set current page number
Try
{// Handle abnormal Address Bar values
M_intcurrentpage = convert. toint32 (request. querystring ["Ps"]);
If (m_intcurrentpage> m_inttotalpage)

M_intcurrentpage = m_inttotalpage;

}
Catch
{
// M_intcurrentpage = m_intcurrentpage;
}
}
// Set the page content to get the size of the current page
If (m_intcurrentpage <m_inttotalpage)
{
M_intpagesize = m_intcurrentpage <m_inttotalpage? M_intpagesize: (m_intarticlelength-m_intpagesize * (m_intcurrentpage-1 ));
M_strret + = p_strcontent.substring (m_intpagesize * (m_intcurrentpage-1), m_intpagesize );
}
Else if (m_intcurrentpage = m_inttotalpage)
{
Int mm_intpagesize = m_intarticlelength-m_intpagesize * (m_intcurrentpage-1 );
M_strret + = p_strcontent.substring (m_intarticlelength-mm_intpagesize );
}

String m_strpageinfo = "";
For (INT I = 1; I <= m_inttotalpage; I ++)
{
If (I = m_intcurrentpage)
M_strpageinfo + = "[" + I + "]";
Else
M_strpageinfo + = "<a href =? PS = "+ I +"> ["+ I +"] </a> ";

}
If (m_intcurrentpage> 1)
M_strpageinfo = "<a href =? PS = "+ (m_intcurrentpage-1) +"> previous page </a> "+ m_strpageinfo;
If (m_intcurrentpage <m_inttotalpage)
M_strpageinfo + = "<a href =? PS = "+ (m_intcurrentpage + 1) +"> next page </a> ";
// Display the page numbers.
// This. showpagenumber. Text = "<p> </P>" + m_strpageinfo;
Page = "<p> </P>" + m_strpageinfo;

}
Else
{
M_strret + = p_strcontent;
}
Return m_strret;
}
}

 

Background call:

Protected void page_load (Object sender, eventargs E)
{

Int id = int. parse (request. querystring ["myid"]. tostring ());

Dataset DS = exambll. selectconetxtbyexaminationid (ID );

String STR = Ds. Tables [0]. Rows [0] ["context"]. tostring ();

Label1.text = articlepagebase. outputbysize (STR, request, ID );
Showpagenumber. Text = articlepagebase. page;

}

 

Front-end code:

<Div>
<Asp: Label id = "label1" runat = "server" text = "label"> </ASP: Label>
<Asp: Label id = "showpagenumber" font-size = "14px" runat = "server"> </ASP: Label>
</Div>

 

 

 

Pagination Based on separators:

# Region page start
Int page = 1; // The initial Page code. The first page is displayed.
String mypage = "1 ";
If (request. querystring ["page"]! = NULL)
{
Mypage = request. querystring ["page"];
}
If (mypage! = NULL) // when the page is not loaded for the first time, the result is null. Therefore, you need to determine
{
Page = convert. toint32 (mypage );
}

String content = Ds. Tables [0]. Rows [0] ["news_context"]. tostring ();
// The above content can be obtained from the database. For the convenience of demonstration, write the content directly. Use <p> to separate the content to be obtained.

String [] strcontent = NULL;

Strcontent = filesplit (content); // call the filesplit method to obtain the content in the array format

If (strcontent [page-1]! = NULL)
{

This. label1.text = strcontent [page-1]. tostring (); // display content
}
Else
{
This. label1.text = "NO content ";

}
String adpager = string. empty;

If (Int. parse (mypage)> 1)
{
Int qianpage = int. parse (mypage)-1;
Adpager + = "<a href = zixundetails. aspx? Id = "+ ID +" & page = "+ qianpage +"> previous page </a> ";
}

For (INT I = 0; I <strcontent. length; I ++)
{// Obtain the number of pages in the cyclic Array
Int npage = 0;
If (strcontent [I]! = NULL)
{
Npage = I + 1;
X = I + 1;
Adpager + = "<a href = zixundetails. aspx? Id = "+ ID +" & page = "+ npage +"> "+ npage +" </a> & nbsp ;";

}
}
If (Int. parse (mypage) <X) // strcontent. length)
{
Int xiapage = int. parse (mypage) + 1;

Adpager + = "<a href = zixundetails. aspx? Id = "+ ID +" & page = "+ xiapage +"> next page </a> ";

}
This. showpagenumber. Text = adpager. tostring (); // display the page

# Endregion end of page

 

 

Call method:

# Values separated by region
Public String [] filesplit (string contents)
{

Int fileindex = 0;
String [] splitfile = new string [10];
While (contents. length> 3000 & fileindex <9)
{

If (contents. indexof ("(* ^__ ^ *)", 3000) <0) break;

Splitfile [fileindex] = contents. substring (0, contents. indexof ("(* ^ __^ *)", 3000); // note that 10 is the number of words, and I use 10 for testing, you can set it based on your news page. I think it should be at least 200 words. Haha ......
Contents = contents. Remove (0, splitfile [fileindex]. Length );
Fileindex ++;
}
Splitfile [fileindex] = contents;
Return splitfile;
}
# Endregion

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.