My paging experience in the press release system of the program Life Series

Source: Internet
Author: User

After I showed my job to the Minister, I asked for real paging, instead of using the pagination function provided by the gridview. Indeed, I think that is not good, so let's do it, after doing so, you can turn to the right, hahaha!

--- Pagination ----

Step 1: Stored Procedure Create procedure [DBO]. [news_selectbyindex]

@ Startindex int,

@ Endindex int



With temptbl (

Select row_number () over (order by ID) as row, * From News


Select * From temptbl where row between @ startindex and @ endindex


Step 2: add the corresponding method in sqlhelper

Public sqldatareader executenewsreader (commandtype parameter type, Params sqlparameter [] partition parms)




Conn = getconn ();

String optional text = "news_selectbyindex ";

Cmd = new sqlcommand (plain text, Conn );

Cmd. commandtype = primitive type;

Cmd. Parameters. addrange (partition parms );

Sqldatareader RDR = cmd. executereader (commandbehavior. closeconnection );

Cmd. Parameters. Clear ();

Return RDR;




Conn. Close ();




Step 3: add the aspnetpager control to the page

Add to top

<% @ Register Assembly = "aspnetpager" namespace = "Wuqi. webdiyer" tagprefix = "webdiyer" %>

<Webdiyer: aspnetpager id = "aspnetpager1" cssclass = "paginator" currentpagebutt runat = "server" alwaysshow = "true" firstpagetext = "Homepage" lastpagetext = "last" homepage = "Next" pagesize = ""8" prevpagetext = "Previous Page" showcustominfosection = "Left" showinputbox = "never" custominfotextalign = "Left" layouttype = "table">

</Webdiyer: aspnetpager>

Step 4: Add CSS attributes for the aspnetpager Control

. Paginator


Font: 12px Arial, Helvetica, sans-serif;

Padding: 10px 20px 10px 0;

Margin: 0px;


. Paginator


Border: solid 1px # CCC;

Color: # 0063dc;

Cursor: pointer;

Text-Decoration: none;


. Paginator A: visited


Padding: 1px 6px;

Border: solid 1px # DDD;

Background: # FFF;

Text-Decoration: none;


. Paginator. Cardiopulmonary Bypass


Border: 1px solid # F50;

Font-weight: 700;

Color: # F50;

Background-color: # ffeee5;


. Paginator A: hover


Border: solid 1px # F50;

Color: # f60;

Text-Decoration: none;


. Paginator A,. paginator A: visited,. paginator. Cardiopulmonary,. paginator A: hover


Float: left;

Height: 16px;

Line-Height: 16px;

Min-width: 10px;

_ Width: 10px;

Margin-Right: 5px;

Text-align: center;

White-space: nowrap;

Font-size: 12px;

Font-family: Arial, simsun;

Padding: 0 3px;


Step 5: Compile the page background code

Public void binddata ()


// Bind statement

Repnews. datasource = new sqlhelper (). executenewsreader (commandtype. storedprocedure,

New sqlparameter ("@ startindex", aspnetpager1.startrecordindex ),

New sqlparameter ("@ endindex", aspnetpager1.endrecordindex ));

Repnews. databind ();

This. aspnetpager1.custominfohtml = string. format ("Current page {0}/{1} contains {2} records per page {3}", new object [] {This. aspnetpager1.currentpageindex, this. aspnetpager1.pagecount, this. aspnetpager1.recordcount, this. aspnetpager1.pagesize });


Protected void aspnetpager1_pagechanged (Object SRC, eventargs E)


Binddata ();


Then, modify all the background code and use binddate (), for example, page_load (), after deleting the news category, and so on.

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: 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.