asp.net paging function Implementation _ practical skills

Source: Internet
Author: User

Talk about the idea of paging

Here the paging used a component AspNetPage.dll, this component can be downloaded to the Internet, I do not provide a

Add the most recent to the toolbox so we can drag and drop the same as other controls

As Figure DataPage is in the toolbox, as to how to add your Baidu bar

Drag and drop to the page as shown

This is the result of my style after the display, how is it not you want, if not you can also modify the style style

Let's see how it's going to work.

 <webdiyer:aspnetpager id= "AspNetPager1" runat= "Server" alwaysshow= "true" 
      pagesize= "" cssclass= "Paginator"  currentpagebuttonclass= "CPB"
     Lastpagetext= "Last" firstpagetext= "Home" prevpagetext= "last Page" nextpagetext= "Next"
      urlpaging= "false" Numericbuttontextformatstring= ' {0} ' 
      showcustominfosection= ' left ' onpagechanged= ' aspnetpager1_pagechanged ' Custominfotextalign= "left" layouttype= "Table" >
 </webdiyer:AspNetPager>

This is the code generated by the paging control

Which shows the first page, Prev, Next, last, these can be in the attribute to set out what to show, can also be pictures, specific to rely on your own to study the

PageSize property to set the number of bars displayed per page

Urlpageing This property can set the way in which pagination is committed, and when set to true, use URL Pass-through parameter submission (the page will be refreshed after your own test so I am not submitting using URL pass parameters)

The Showcustominfosection setting shows the location with the left and right three values, and what do you mean, you know?

Onpagechanged This event for the click of the paging button when the event, the code

 Paging event
    protected void aspnetpager1_pagechanged (object sender, EventArgs e)
    {
      BindView (viewstate[) DataSource "] as list<tbl_teacher>);
    }

Here I call a custom bound data source method BindView

 Bound 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 ("Current {0}/{1} page total {2} records per page {3}", new object[]

{this. Aspnetpager1.currentpageindex, this. Aspnetpager1.pagecount, this. Aspnetpager1.recordcount, this. Aspnetpager1.pagesize});

    

Here is the binding data source, in order to facilitate my use of LINQ to do pagination, of course, you can let you change, you can use stored procedures, can also be passed directly with SQL query, mainly on two parameters,

A display of the number of bars, a current page, I believe it is not difficult for you

Here basically has posted all the code, may describe is not very clear, but also so, I have a limited level. The following two styles are attached:

<style type= "TEXT/CSS" >/* Pat NET style * * Paginator {font:11px Arial, Helvetica, sans-serif;padding:10px 20px 10px 0; ma
rgin:0px;} . paginator a {padding:1px 6px; border:solid 1px #ddd; background: #fff; text-decoration:none;margin-right:2px}. Paginat or 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.
{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>

Summary : This paging component is separated from data and provides only the ability to display pages, and data can be bound to the data source based on the number of pages and bars recorded by the component, or it is convenient.

If the asp.net implementation of the paging function is not complete description, but also please make up, we study together.

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.