Home>

Talk about the idea of ​​implementing paging

Here the pagination uses a component aspnetpage.dll, you can download this component online,I won't provide it here

Add recent to the toolbox so we can drag and use like other controls

Figure datapage is in the toolbox,As for how to add your Baidu

Drag to the page as shown

This is the effect that I display after I add the style.How is it that i want it?If not you can also modify the style

Let's see how to use it first

<webdiyer:aspnetpager runat="server" alwaysshow="true"
      pagesize="20" cssclass="paginator" currentpagebuttonclass="cpb"
     lastpagetext="last page" firstpagetext="first page" prevpagetext="previous page" nextpagetext="Next page"
      urlpaging="false" numericbuttontextformatstring="{0}"
      showcustominfosection="left" onpagechanged="aspnetpager1_pagechanged" custominfotextalign="left" layouttype="table">
 </webdiyer:aspnetpager>

This is the code generated by the paging control

The home page shown,The previous page, the next page, the last page, these can be set in the properties to display,It can also be a picture,It's up to you to study the specifics

pagesize property sets the number of pages displayed per page

The urlpageing property can set the submission method of pagination.When set to true, use url to pass parameters to submit.So I didn't use url to pass parameters to submit)

The showcustominfosection setting has three values:left, middle, and right.As to what you mean

onpagechanged This event is the event when the paging button is clicked.Send code

//Page break event
    protected void aspnetpager1_pagechanged (object sender, eventargs e)
    {
      bindview (viewstate ["datasource"] as list<tbl_teacher>);
    }

Here I call a custom binddata method bindview

//Binding data source
    public void bindview (list<tbl_teacher>ls)
    {
      this.aspnetpager1.recordcount=ls.count ();
      this.gridview1.datasource=ls.skip ((aspnetpager1.currentpageindex-1) * aspnetpager1.pagesize) .take (aspnetpager1.pagesize);
      this.gridview1.databind ();
      this.aspnetpager1.custominfohtml=string.format ("The current {0}/{1} page total {2} records {3} records per page", new object []
{this.aspnetpager1.currentpageindex, this.aspnetpager1.pagecount, this.aspnetpager1.recordcount, this.aspnetpager1.pagesize});
    }

Here is the binding data source,For convenience, I use linq for paging.Of course, you can change it here.You can use stored procedures,You can also pass directly using SQL query, mainly two parameters,

One displayed bar number,A current number of pages,I believe it is not difficult for you

At this point basically all the code has been posted,May not be very clear,But that's it,My level is limited.Paste two styles below:

<style type="text/css">
/*Pat net * /
.paginator {font:11px arial, helvetica, sans-serif;padding:10px 20px 10px 0;margin:0px;}
.paginator a {padding:1px 6px;border:solid 1px #ddd;background:#fff;text-decoration:none;margin-right:2px}
.paginator a:visited {padding:1px 6px;border:solid 1px #ddd;background:#fff;text-decoration:none;}
.paginator .cpb {padding:1px 6px;font-weight:bold;font-size:13px;border:none}
.paginator a:hover {color:#fff;background:#ffa501;border-color:#ffa501;text-decoration:none;}
/* Taobao style * /
.paginator {font:12px arial, helvetica, sans-serif;padding:10px 20px 10px 0;margin:0px;}
.paginator a {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 .cpb {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 .cpb, .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;}
 </style>

to sum up:This paging component is separate from the data.Only the function of displaying the number of pages is provided.The data can be bound to the data source based on the number of pages and the number of records recorded by the component.Still very convenient.

If the description of asp.net's paging function is not complete,Please also make up for it,Everyone learns together.

  • Previous Briefly introduce the application of category in iOS development
  • Next C # method of reading and writing INI files