asp.net a method to generate HTML pagination directly using background-practical skills

Source: Internet
Author: User

The example of this article tells the asp.net to use the backstage realization to generate the HTML pagination directly, is a more practical function. Share for everyone to use for reference. The specific methods are as follows:

1. Set up stored procedures:

ALTER procedure [dbo]. [P_news_query]
@Page int
as
begin
Select Top 5 new_id,new_title,new_url,new_content_text,create_time,user_name from 
 (select *,row_number () over (order by new_id Desc) as RowNumber  from
    (select New_id,new_title,new_url,new_ Content_text,
        dbo.f_convertdate (a.create_time) create_time, b.user_name from Xs_new a left
        join Xs_users B on B . User_no=a.create_user
) TI 
) a 
 where a.rownumber> (@Page-1) *5

end

Currently the experiment is 5 data per page, the current page number can be passed in

2. The foreground defines a div for displaying

 <div id= "Divpage" runat= "Server" class= "Divpage" >
  </div>

3. Background based on incoming parameters to spell HTML

At present, the pattern of Imitation Blog Park, before and after showing 5, superfluous plus ... After the last one. The specific code is as follows:

  StringBuilder sbr = new StringBuilder ();
  int itotalcount = Pagelogic.querynewscount ();
  int ipage = 1;
  if (request["p"]!= null) {ipage = Convert.ToInt32 (request["P"]);
  int ipagecount = 5;
  int itotalpage = Itotalcount/ipagecount;
  if (itotalcount% Ipagecount > 0) {itotalpage = 1; } if (IPage!= 1) {sbr. Append ("<a href=\" news.aspx?p= "+ (IPage-1)."
  ToString () + "\" > Prev </a> "); } if (Itotalpage <=) {for (int i = 1; I <= itotalpage; i++) {if (i = = IPage) {sbr.
   Append ("<a href=\" news.aspx?p= "+ i.tostring () +" \ "class=\" pageselect\ ">" + i.tostring () + "</a>"); else {sbr.
   Append ("<a href=\" news.aspx?p= "+ i.tostring () +" \ ">" + i.tostring () + "</a>"); {SBR}}} else {if (IPage-5 > 2 && ipage + 7 < itotalpage)/.
   Append ("<a href=\" news.aspx?p=1\ "&GT;1&LT;/A&GT; ..."); for (int i = IPage-5 I <= ipage + 5; i++) {if (i = = Ipage) {sbr.
 Append ("<a href=\" news.aspx?p= "+ i.tostring () +" \ "class=\" pageselect\ ">" + i.tostring () + "</a>"); else {sbr.
 Append ("<a href=\" news.aspx?p= "+ i.tostring () +" \ ">" + i.tostring () + "</a>"); }} SBR.

 Append ("... <a href=\" news.aspx?p=) + itotalpage.tostring () + ">" + itotalpage.tostring () + "</a>"); else if (IPage-5 <= 2)//front is not enough, there is an extra {for (int i = 1; I <= i++) {if (i = = IPage) {sbr.
 Append ("<a href=\" news.aspx?p= "+ i.tostring () +" \ "class=\" pageselect\ ">" + i.tostring () + "</a>"); else {sbr.
 Append ("<a href=\" news.aspx?p= "+ i.tostring () +" \ ">" + i.tostring () + "</a>"); }} SBR.
 Append ("... <a href=\" news.aspx?p=) + itotalpage.tostring () + ">" + itotalpage.tostring () + "</a>"); else if (IPage + 7 >= itotalpage)//front superfluous, behind insufficient {sbr.
   Append ("<a href=\" news.aspx?p=1\ "&GT;1&LT;/A&GT; ..."); for (int i = ITotalPage-10 I <= Itotalpage; i++) {if (i = = IPage) {sbr.
 Append ("<a href=\" news.aspx?p= "+ i.tostring () +" \ "class=\" pageselect\ ">" + i.tostring () + "</a>"); else {sbr.
 Append ("<a href=\" news.aspx?p= "+ i.tostring () +" \ ">" + i.tostring () + "</a>"); }} if (IPage!= itotalpage) {sbr. Append ("<a href=\" news.aspx?p= "+ (IPage + 1)."
  ToString () + "\" > Next page </a> "); } divpage.innerhtml = sbr.
  ToString ();
  Rptnews.datasource = Pagelogic.querynews (ipage);

 Rptnews.databind ();

4. The test effect is shown in the following illustration:

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.