ASP. NET: A common paging Function

Source: Internet
Author: User
Function:
1. Each page is set to display 9 pages, more than 9 pages, + 1 page after 5 pages (can be modified as needed)
2. Set CSS styles by yourself
3. Nothing Code Generation, facilitating Search Engine Optimization

// Pagination Program
Objpds = new pageddatasource ();
Objpds. datasource = dttable. defaultview; // bind a data source
Objpds. allowpaging = true;
Objpds. pagesize = 10; // Number of pages
Int curpage;
Int cshi;
Int jshi;
Int zyes = int32.parse (objtp.pagecount. tostring ());
This. tjixx. Text = "Total <font color = Red>" + dttable. Rows. Count + "</font> information ";
This. tjixx. Text + = "| Total <font color = Red>" + zyes + "</font> pages ";
If (request. querystring ["page"]! = NULL)
{
If (int32.parse (request. querystring ["page"])> zyes)
Curpage = zyes;
Else
Curpage = int32.parse (request. querystring ["page"]);
}

Else
{
Curpage = 1;
}

If (zyes <= 9)
{
Cshi = 1;
Jshi = zyes;

}
Else
{
If (curpage <= 5)
{
Cshi = 1;
Jshi = 9;

}

Else
{

Cshi = curpage-4;
Int jshils = curpage + 4;
If (jshils> zyes)
Jshi = zyes;
Else
Jshi = curpage + 4;

}
}
Objpds. currentpageindex = curpage-1;
Stringbuilder m_strpageinfo = new stringbuilder ();
For (INT I = cshi; I <= jshi; I ++)
{
If (I = int32.parse (curpage. tostring ()))
M_strpageinfo.append ("<SPAN class = \" dqye \ "> <strong>" + I + "</strong> </span> ");
Else
M_strpageinfo.append ("<SPAN class = \" qtye \ "> <strong> <a href = \" newslist_ej "+ request. querystring ["wzcat"] + "_ page" + I + ". HTML \ ">" + I + "</a> </strong> </span> ");
}
This. yemsl. Text = m_strpageinfo.tostring ();

If (! Objpps. isfirstpage)
{

Linkpre. navigateurl = "newslist_ej" + request. querystring ["wzcat"] + "_ page" + convert. tostring (curpage-1 );
Linkpre. navigateurl + = ". html ";
}
If (! Objpps. islastpage)
{
Linknext. navigateurl = "newslist_ej" + request. querystring ["wzcat"] + "_ page" + convert. tostring (curpage + 1 );
Linknext. navigateurl + = ". html ";
}
Linkfirstpage. navigateurl = "newslist_ej" + request. querystring ["wzcat"] + "_ page1 ";
Linkfirstpage. navigateurl + = ". html ";
Linkendpage. navigateurl = "newslist_ej" + request. querystring ["wzcat"] + "_ page" + objpd.pagecount. tostring ();
Linkendpage. navigateurl + = ". html ";
This. datalist4.datasource = objpds; // bind the paging data.
This. datalist4.databind ();

// Aspx file:

Paging part:

<Div align = "center"> <asp: hyperlink id = "linkfirstpage" runat = "server" font-underline = "false"> homepage </ASP: hyperlink> & lt; & lt;
<Asp: hyperlink id = "linkpre" runat = "server" font-underline = "false"> previous page </ASP: hyperlink>
<Asp: literal id = "yemsl" runat = "server"> </ASP: literal>
<Asp: hyperlink id = "linknext" runat = "server" font-underline = "false"> next page </ASP: hyperlink> & nbsp;
& Gt; <asp: hyperlink
Id = "linkendpage" runat = "server" font-underline = "false"> last page </ASP: hyperlink> | <asp: literal
Id = "tjixx" runat = "server"> </ASP: literal> </div>

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.