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\ ">1</A> ..."); 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\ ">1</A> ..."); 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.