asp.net article pagination display implementation Code _ Practical skills

Source: Internet
Author: User
Copy Code code as follows:

protected void Page_Load (object sender, EventArgs e)
{
String str = "things happen on the May 14 night 23:30, Langfang Teachers ' College 1th dormitory has a vicious fight killings, because 1th building more complex, there are sports students, English schools, education institutes and other student accommodation, the situation was more chaotic. The victim is a 10-class sports students (immediately facing graduation) and a 11-level education Institute of new students, both sides of the contradiction between the current unknown, on the spot caused 2 dead 1 serious injuries, wound knife lethal. One of them was severed by the killer's throat artery, without rescue, death on the spot; a man was stabbed in the kidney, without rescuing, died on the spot; a man was stabbed to the heart, because the ambulance came after some rescue treatment, has been sent to the local hospital, its current health is unknown. The event lasted until three o'clock in the morning, under the police blockade, the students all dispersed. The second day after the school to the students held large and small no less than 20 meetings, requiring a large number of students to block news, not publicity, the current school attitude is not clear, the deceased family repeatedly contacted the school to beg for the argument, but was blocked in the campus doorway, has not seen the university leaders, also not On May 20, 2012, the school gave a saying to one of the victims ' families how much money you want. The school does not take into account the suffering of the family members of the deceased, white-haired people send black hair, because the university management is not right, the battle has never been blocked, resulting in two dead and one seriously injured. Today, the family members of the deceased urged all media friends and netizens to give their attention to help the deceased family members, to the school a fair, but also the deceased a statement, not for anything else, only for the rest of the deceased. ";
Label1.Text = Outputbysize (str);
}

public string Outputbysize (string p_strcontent)//Paging function
{
String m_strret = "";
int m_intpagesize = 200;//article per page size
int m_intcurrentpage = 1;//Set first page as 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, it is not paged.
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 the value of an abnormal address bar
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 setting gets 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) + "> Prev </a>" + m_strpageinfo;
if (M_intcurrentpage < m_inttotalpage)
M_strpageinfo + + "<a href=?ps=" + (M_intcurrentpage + 1) + "> Next </a>";
Output shows individual page numbers
This. Showpagenumber.text = "<p></p>" + m_strpageinfo;

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

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.