search
HomeBackend DevelopmentC#.Net TutorialRepeater uses AspNetPager paging control under asp.net

1. AspNetPager paging control
Paging is one of the most commonly used functions in Web applications. In ASP.NET, although it comes with a DataGrid (asp.net 1.1) and GridView (asp .net 2.0) control, but its paging function is not satisfactory, such as poor customizability, inability to implement paging function through Url, etc., and sometimes we need to paginate DataList, Repeater or even custom data binding controls, and write them manually Paging code is not only technically difficult and cumbersome, but also has a very low code reuse rate. Therefore, paging has become one of the most troublesome problems for many ASP.NET programmers.
AspNetPager proposes a unique solution to the paging problem in ASP.NET in response to the shortcomings of the ASP.NET paging control. That is, the paging navigation function and the data display function are completely independent, and the user controls the acquisition and processing of data. The display method can be flexibly applied to any place where paging navigation functions need to be implemented, such as implementing paging for data-bound controls such as GridView, DataList, and Repeater, presenting custom paging data, and making image browsing programs, etc., because the AspNetPager control It is independent of the data, so the data to be paged can come from any data source, such as SQL Server, Oracle, Access, mysql, DB2 and other databases, as well as XML files, memory data or data in cache, file systems, etc.
2. Basic attributes:
AlwaysShow:
By default, when the data to be paged is only one page, AspNetPager will automatically avoid displaying any visible content on the page by default. Set this attribute value to When true, AspNetPager will display pagination navigation elements even if the total number of pages is only one.
FirstPageText:
Get or set the text displayed for the first page button.
LastPageText:
Get or set the text displayed for the last page button.
NextPageText:
Get or set the text displayed for the next page button.
PrevPageText:
Get or set the text displayed for the previous page button.
PageSize:
Get or set the number of items displayed on each page. (This value gets or sets the number of data items in the data table that the data rendering control needs to display each time. AspNetPager calculates the total number of pages required to display all data based on this value and RecordCount, which is the value of PageCount.)
CssClass :
The css class name applied to the control
CurrentPageButtonClass:
Gets or sets the cascading style sheet (CSS) class of the current page navigation button of the AspNetPager paging control.
PageIndexBoxType:
Or or set the display type of the page index box, which can be a text box that allows users to enter manually and a drop-down box that can only be selected.
ShowBoxThreshold:
When ShowPageIndexBox is set to Auto (default) and the total number of pages of data to be paged reaches this value, the page index input text box will be automatically displayed. The default value is 30. This option has no effect when ShowPageIndexBox is set to Never or Always.
3. Style:
====== NetEase style=====
.anpager .cpb {background:#1F3A87 none repeat scroll 0 0;border:1px solid #CCCCCC;color: #FFFFFF;font-weight:bold;margin:5px 4px 0 0;padding:4px 5px 0;}
.anpager a {background:#FFFFFF none repeat scroll 0 0;border:1px solid #CCCCCC;color:# 1F3A87;margin:5px 4px 0 0;padding:4px 5px 0;text-decoration:none}
.anpager a:hover{background:#1F3A87 none repeat scroll 0 0;border:1px solid #1F3A87;color:# FFFFFF;}
Property settings: CssClass="anpager" CurrentPageButtonClass="cpb"
====== Paipai.com style=====
.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;}
Properties Settings: CssClass="paginator" CurrentPageButtonClass="cpb"
===== Thunder style=====
.pages { color: #999; }
.pages a, .pages .cpb { text-decoration:none;float: left; padding: 0 5px; border: 1px solid #ddd;background: #ffff;margin:0 2px; font-size:11px; color:#000;}
.pages a:hover { background-color: #E61636; color:#fff;border:1px solid #E61636; text-decoration:none;}
.pages .cpb { font-weight: bold; color: #fff; background : #E61636; border:1px solid #E61636;}
Property settings: CssClass="pages" CurrentPageButtonClass="cpb"
4. How to call:
index.aspx file

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %> 
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %> 
<%@ Register src="hand.ascx" tagname="hand" tagprefix="uc1" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
<title></title> 
<link href="inc/css.css" rel="stylesheet" type="text/css" /> 
<style type="text/css"> 
/*网易风格*/ 
.anpager .cpb {background:#1F3A87 none repeat scroll 0 0;border:1px solid #CCCCCC;color:#FFFFFF;font-weight:bold;margin:5px 4px 0 0;padding:4px 5px 0;} 
.anpager a {background:#FFFFFF none repeat scroll 0 0;border:1px solid #CCCCCC;color:#1F3A87;margin:5px 4px 0 0;padding:4px 5px 0;text-decoration:none} 
.anpager a:hover{background:#1F3A87 none repeat scroll 0 0;border:1px solid #1F3A87;color:#FFFFFF;} 
/*拍拍网风格*/ 
.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;} 
/*迅雷风格*/ 
.pages { color: #999 } 
.pages a, .pages .cpb { text-decoration:none;float: left; padding: 0 5px; border: 1px solid #ddd;background: #ffff;margin:0 2px; font-size:11px; color:#000;} 
.pages a:hover { background-color: #E61636; color:#fff;border:1px solid #E61636; text-decoration:none;} 
.pages .cpb { font-weight: bold; color: #fff; background: #E61636; border:1px solid #E61636;} 
.code{font-weight:bold;color:blue} 
</style> 
</head> 
<body> 
<form id="form1" runat="server"> 
<uc1:hand ID="hand1" runat="server" /> 
<div style="text-align:left; line-height:20px"> 
<asp:Repeater ID="SoftDown" runat="server"> 
<ItemTemplate> 
<div style="border-bottom:1px solid #000000"><%#Eval("E_id")%> <%#Eval("Class")%><br><%#Eval("DownTitle")%><br><%#Eval("PageHome")%></div> 
</ItemTemplate> 
</asp:Repeater> 
<div style="text-align:right; padding-top:10px"> 
<webdiyer:AspNetPager ID="AspNetPager1" runat="server" pagesize="5" CssClass="anpager" onpagechanged="AspNetPager1_PageChanged" 
FirstPageText="首页" LastPageText="尾页" NextPageText="下一页" PrevPageText="上一页" 
ShowMoreButtons="False" ShowPageIndexBox="Never"> 
</webdiyer:AspNetPager></div> 
</div> 
</form> 
</body> 
</html>

index.aspx.cs

using System; 
using System.Collections; 
using System.Configuration; 
using System.Data; 
using System.Linq; 
using System.Web; 
using System.Web.Security; 
using System.Web.UI; 
using System.Web.UI.HtmlControls; 
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts; 
using System.Xml.Linq; 
using System.Data.SqlClient; 
using GHSqlConn; 
using Wuqi.Webdiyer; 
public partial class Default2 : System.Web.UI.Page 
{ 
protected void Page_Load(object sender, EventArgs e) 
{ 
if (!IsPostBack) { 
SqlConnection conn = DB.getConnection(); 
conn.Open(); 
SqlCommand Count = new SqlCommand(); 
Count.Connection = conn; 
Count.CommandText = "select count(*) from T_SoftDown1"; 
AspNetPager1.RecordCount = (int)Count.ExecuteScalar(); 
//Response.Write(AspNetPager1.RecordCount); 
conn.Close(); 
BindData(); 
} 
} 
public void BindData() 
{ 
SqlConnection conn = DB.getConnection(); 
string sql = "select * from T_SoftDown1 order by E_id desc";//这句在大型数据中应该用:select top查询语句 
SqlDataAdapter da = new SqlDataAdapter(sql, conn); 
DataSet ds = new DataSet(); 
da.Fill(ds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "temptbl"); 
DataTable dt = ds.Tables["temptbl"]; 
SoftDown.DataSource=dt; 
SoftDown.DataBind(); 
} 
protected void AspNetPager1_PageChanged(object src, EventArgs e) 
{ 
//AspNetPager1.CurrentPageIndex = e.NewPageIndex; 
BindData(); 
} 
}

For more articles related to Repeater using AspNetPager paging control under asp.net, please pay attention to the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Developing with C# .NET: A Practical Guide and ExamplesDeveloping with C# .NET: A Practical Guide and ExamplesMay 12, 2025 am 12:16 AM

C# and .NET provide powerful features and an efficient development environment. 1) C# is a modern, object-oriented programming language that combines the power of C and the simplicity of Java. 2) The .NET framework is a platform for building and running applications, supporting multiple programming languages. 3) Classes and objects in C# are the core of object-oriented programming. Classes define data and behaviors, and objects are instances of classes. 4) The garbage collection mechanism of .NET automatically manages memory to simplify the work of developers. 5) C# and .NET provide powerful file operation functions, supporting synchronous and asynchronous programming. 6) Common errors can be solved through debugger, logging and exception handling. 7) Performance optimization and best practices include using StringBuild

C# .NET: Understanding the Microsoft .NET FrameworkC# .NET: Understanding the Microsoft .NET FrameworkMay 11, 2025 am 12:17 AM

.NETFramework is a cross-language, cross-platform development platform that provides a consistent programming model and a powerful runtime environment. 1) It consists of CLR and FCL, which manages memory and threads, and FCL provides pre-built functions. 2) Examples of usage include reading files and LINQ queries. 3) Common errors involve unhandled exceptions and memory leaks, and need to be resolved using debugging tools. 4) Performance optimization can be achieved through asynchronous programming and caching, and maintaining code readability and maintainability is the key.

The Longevity of C# .NET: Reasons for its Enduring PopularityThe Longevity of C# .NET: Reasons for its Enduring PopularityMay 10, 2025 am 12:12 AM

Reasons for C#.NET to remain lasting attractive include its excellent performance, rich ecosystem, strong community support and cross-platform development capabilities. 1) Excellent performance and is suitable for enterprise-level application and game development; 2) The .NET framework provides a wide range of class libraries and tools to support a variety of development fields; 3) It has an active developer community and rich learning resources; 4) .NETCore realizes cross-platform development and expands application scenarios.

Mastering C# .NET Design Patterns: From Singleton to Dependency InjectionMastering C# .NET Design Patterns: From Singleton to Dependency InjectionMay 09, 2025 am 12:15 AM

Design patterns in C#.NET include Singleton patterns and dependency injection. 1.Singleton mode ensures that there is only one instance of the class, which is suitable for scenarios where global access points are required, but attention should be paid to thread safety and abuse issues. 2. Dependency injection improves code flexibility and testability by injecting dependencies. It is often used for constructor injection, but it is necessary to avoid excessive use to increase complexity.

C# .NET in the Modern World: Applications and IndustriesC# .NET in the Modern World: Applications and IndustriesMay 08, 2025 am 12:08 AM

C#.NET is widely used in the modern world in the fields of game development, financial services, the Internet of Things and cloud computing. 1) In game development, use C# to program through the Unity engine. 2) In the field of financial services, C#.NET is used to develop high-performance trading systems and data analysis tools. 3) In terms of IoT and cloud computing, C#.NET provides support through Azure services to develop device control logic and data processing.

C# .NET Framework vs. .NET Core/5/6: What's the Difference?C# .NET Framework vs. .NET Core/5/6: What's the Difference?May 07, 2025 am 12:06 AM

.NETFrameworkisWindows-centric,while.NETCore/5/6supportscross-platformdevelopment.1).NETFramework,since2002,isidealforWindowsapplicationsbutlimitedincross-platformcapabilities.2).NETCore,from2016,anditsevolutions(.NET5/6)offerbetterperformance,cross-

The Community of C# .NET Developers: Resources and SupportThe Community of C# .NET Developers: Resources and SupportMay 06, 2025 am 12:11 AM

The C#.NET developer community provides rich resources and support, including: 1. Microsoft's official documents, 2. Community forums such as StackOverflow and Reddit, and 3. Open source projects on GitHub. These resources help developers improve their programming skills from basic learning to advanced applications.

The C# .NET Advantage: Features, Benefits, and Use CasesThe C# .NET Advantage: Features, Benefits, and Use CasesMay 05, 2025 am 12:01 AM

The advantages of C#.NET include: 1) Language features, such as asynchronous programming simplifies development; 2) Performance and reliability, improving efficiency through JIT compilation and garbage collection mechanisms; 3) Cross-platform support, .NETCore expands application scenarios; 4) A wide range of practical applications, with outstanding performance from the Web to desktop and game development.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),