asp.net implementation of simple pagination example _ practical skills

Source: Internet
Author: User

This article illustrates the method of asp.net to implement simple pagination. Share to everyone for your reference.

The implementation methods are as follows:

Copy Code code as follows:
<summary>
Paging content
</summary>
<param name= "Size" > Page size </param>
<param name= "Count" > Number of pages </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 Window Target
target = string. IsNullOrEmpty (target)? "_top": Target;
2> Total 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} ' >[home]</a>", target);
Strhtml.appendformat ("<a href= ' {0} ' target= ' {1} ' >[page]</a>", String. Format (pattern, currendIndex-1), target);
}
Else
{
Strhtml.append ("<span class= ' disabled ' >[home]</span> <span class= ' disabled ' >[on a page]</span>");
}
#endregion

#region the middle part
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 Handling
if (Currendindex = = PageCount)
{
Strhtml.append ("<span class= ' disabled ' >[next page]</span><span class= ' disabled ' >[' last]</span>");
Strhtml.appendformat ("Total ({0}) page", 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]</a>", String.) Format (pattern, PageCount), target);
Strhtml.appendformat ("<label> total ({0}) page </label>", PageCount);
}
#endregion

Strhtml.append ("</span>");

return strhtml.tostring ();
}

I hope this article will help you with the ASP.net program design.

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.