Asp.net implements simple paging instances and asp.net paging instances

Source: Internet
Author: User

Asp.net implements simple paging instances and asp.net paging instances

This example describes how to implement simple paging in asp.net. Share it with you for your reference.

The specific implementation method is as follows:

Copy codeThe Code is as follows: // <summary>
/// Paging content
/// </Summary>
/// <Param name = "size"> page size </param>
/// <Param name = "count"> page count </param>
/// <Param name = "currendIndex"> current page </param>
/// <Param name = "pattern"> url mode: demo. aspx? Page = {0} </param>
/// <Param name = "target"> window mode </param>
/// <Returns> </returns>
Public static string get_pagenation (int size,
Int count,
Int currendIndex,
String pattern,
String target)
{
// 1> open the window Target
Target = string. IsNullOrEmpty (target )? "_ Top": target;
// 2> total number of pages
Int pageCount = count/size;
PageCount = pageCount * size = count? PageCount: pageCount + 1;
// 3> paging content
StringBuilder strHtml = new StringBuilder ();
StrHtml. Append ("<span class = 'pagenation'> ");
 
# Region Header Processing
If (currendIndex> 1)
{
StrHtml. AppendFormat ("<a href = '1' target = '{0}'> [homepage] </a>", target );
StrHtml. appendFormat ("<a href = '{0}' target = '{1}'> [Previous Page] </a>", string. format (pattern, currendIndex-1), target );
}
Else
{
StrHtml. Append ("<span class = 'Disabled '> [homepage] </span> <span class = 'Disabled'> [Previous Page] </span> ");
}
# Endregion
 
# Region intermediate section
Int I = 1;
 
Int right = (currendIndex + 4)> pageCount? PageCount: currendIndex + 4;
If (currendIndex> 6)
{
I = currendIndex-5;
}
Else
{
Right = pageCount> = 10? 10: pageCount;
}
For (; I <= right; I ++)
{
If (I = currendIndex)
{
StrHtml. AppendFormat ("<font class = 'current'> {0} </font>", I );
StrHtml. AppendLine ();
Continue;
}
StrHtml. appendFormat ("<a href = '{0}' target = '{1}'> [{2}] </a>", string. format (pattern, I), target, I );
StrHtml. AppendLine ();
}
# Endregion
 
# Region tail Processing
If (currendIndex = pageCount)
{
StrHtml. Append ("<span class = 'Disabled '> [Next Page] </span> <span class = 'Disabled'> [last page] </span> ");
StrHtml. AppendFormat ("Total ({0}) pages", pageCount );
}
Else
{
StrHtml. appendFormat ("<a href = '{0}' target = '{1}'> [Next Page] </a>", string. format (pattern, currendIndex + 1), target );
StrHtml. appendFormat ("<a href = '{0}' target = '{1}'> [last page] </a>", string. format (pattern, pageCount), target );
StrHtml. AppendFormat ("<label> total ({0}) pages </label>", pageCount );
}
# Endregion
 
StrHtml. Append ("</span> ");
 
Return strHtml. ToString ();
}

I hope this article will help you design your asp.net program.

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.