How to understand the paging control of asp.net
This article introduces you how to understand the asp.net paging control, the content is very detailed, interested friends can refer to, hope to be helpful to you.
I. explanation
AspNetPager.dll this paging control is mainly used for asp.net webform websites, and the code will be sorted out as follows
II. Code
1. First add a reference to the test page Default.aspx page
2. Write a Repeater list control to display data
3. Add
The PageSize property is used to set the number of displays per page
4. Background code binding
/ / Test data source
Private void ShowNews () {String strSql = String.Format ("select * from News order by time asc"); DataTable dtbl = Access.ExecuteDataTable (strSql, null); this.rptNews.DataSource = Access.GetPageDataSource (AspNetPager1, AspNetPager1.CurrentPageIndex-1, dtbl); this.rptNews.DataBind ();}
Access is a test database access class, which is provided to you in the final Demo
5. Paging control clicks the page number event
/ / paging protected void AspNetPager1_PageChanging (object src, Wuqi.Webdiyer.PageChangingEventArgs e) {this.AspNetPager1.CurrentPageIndex = e.NewPageIndex; ShowNews ();}
Finally, I send you the whole page of code:
Default.aspx
Asp.net paging control .aboutcontentnr {width:100%; height:auto;}
Default.aspx.cs
Using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Data;public partial class Default: System.Web.UI.Page {protected void Page_Load (object sender, EventArgs e) {if (! IsPostBack) {ShowNews ();}} / / Test data source private void ShowNews () {String strSql = String.Format ("select * from News order by time asc") DataTable dtbl = Access.ExecuteDataTable (strSql, null); this.rptNews.DataSource = Access.GetPageDataSource (AspNetPager1, AspNetPager1.CurrentPageIndex-1, dtbl); this.rptNews.DataBind ();} / / Page Click event protected void AspNetPager1_PageChanging (object src, Wuqi.Webdiyer.PageChangingEventArgs e) {this.AspNetPager1.CurrentPageIndex = e.NewPageIndex; ShowNews ();}}
III. Demo
AspNetPager (dll)
AspNetPage (Demo)
On how to understand the asp.net paging control to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.