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.