Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand the paging control of asp.net

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report