ASP. NET paging technology

Source: Internet
Author: User

The following is a self-compiled Asp.net paging method. I hope to give you more instructions.
Public static stringbuilder pagebtn (INT currentpage, int numinoneline, string URL, pageddatasource PPS) // returns the index string. numinoneline indicates the number of indexes per row, and currentpage indicates the current page;
{
Stringbuilder sb = new stringbuilder ();
Int currentline; // The current index row.

If (currentpage % numinoneline! = 0) // determines whether the current page is an integer multiple of the number of indexes in each row;
{
Currentline = currentpage/numinoneline + 1;
}
Else
{
Currentline = currentpage/numinoneline;
}
// Add the connection of the last index row
If (currentline = 1)
{
SB. append ("<& nbsp ");
}
Else
{
SB. append ("<a href = '");
SB. append (URL );
SB. append ("? Currentpage = ");
SB. append (convert. tostring (currentLine-1) * numinoneline ));
SB. append ("'><</A> & nbsp ");
}

// Add a page number index
For (INT I = 1; I <= numinoneline; I ++)
{
// <A href = "datalist. aspx" style = "color: Red"> [] </a>
If (currentline-1) * numinoneline + I <= PPS. pagecount) // determines whether the page number is out of bounds;
{
If (currentline-1) * numinoneline + I = currentpage) // you can check whether the index page number is the current page.
{
SB. append ("& nbsp <font style = 'color: red; text-Decoration: none; '> ");
SB. append (currentpage. tostring ());
SB. append ("</font> & nbsp ");
}
Else
{

SB. append ("<a href = '");
SB. append (URL );
SB. append ("? Currentpage = ");
SB. append (convert. tostring (currentline-1) * numinoneline + I ));
SB. append ("'> [");
SB. append (convert. tostring (currentline-1) * numinoneline + I ));
SB. append ("] </a> & nbsp ");
}
}
}

Int totalline; // defines the total number of indexed rows.
If (PPS. pagecount % numinoneline! = 0) // determines whether the total number of pages is an integer multiple of the number of indexes in each row;
{
Totalline = PPS. pagecount/numinoneline + 1;
}
Else
{
Totalline = PPS. pagecount/numinoneline;
}
// Add the next index row
If (currentline = totalline)
{
SB. append ("> ");
}
Else
{
SB. append ("<a href = '");
SB. append (URL );
SB. append ("? Currentpage = ");
SB. append (convert. tostring (currentline * numinoneline + 1 ));
SB. append ("'>></A> ");
}

Return Sb;

}

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.