


Detailed code explanation about repeater and paging effects (ASP)
The Repeater control is a data-binding container control that can generate a list of each item and can use templates to define the layout of each item on the web page. This article introduces this in detail. Let’s take a look at it with the editor.
The Repeater control is a data binding container control. It can generate a list of each item and can use templates to define the properties of each item on the web page. layout. When the page runs, the control repeats this layout for each item in the data source.
Use the repeater control with a template
To use the repeater control, you need to create a template that defines the content layout of the control. Templates can contain any combination of markup and controls. If the template is not defined, or if the template contains no elements, the control does not appear on the page when the application runs.
ItemTemplate: Contains HTML elements and controls that are rendered once for each data item in the data source.
AlternatingItemTemplate : Format alternating data items (contains HTML elements and controls to be rendered once for each data item in the data source. Typically, you can use this template to create different appearances for alternating items, For example, specify a background color that is different from the color specified in the ItemTemplate).
SeparatorTemplate : Format the separator (the element contained between each item that is rendered.).
HeaderTemplate : Format the header (contains text and controls that are rendered separately at the beginning of the list.).
FooterTemplate : Format the footer (contains text and controls that are rendered separately at the end of the list.).
RepeaterPagingThe effect is as follows:
Front desk code:
<body> <asp:Repeater ID="Repeater1" runat="server"> <HeaderTemplate> <p style="background-color:#988c6e;width:400px;padding-top:5px;padding-bottom:5px;margin-left:30px;margin-top:30px;border-radius:5px;color:#fff;font-weight:bold;"><span style="padding-left:30px;">用户名</span><span style="padding-left:100px;">注册时间</span><span style="padding-left:90px;">访问量</span></p> <table style="margin-left:30px;margin-top:30px;"> </HeaderTemplate> <ItemTemplate> <tr> <td style="width:120px;text-align:left; padding-left:20px;"><%#Eval("Username") %></td> <td style="width:170px;text-align:left; "><%#Eval("RegistrationTime") %></td> <td style="width:50px;text-align:left; "><%#Eval("AccessAmount") %></td> </tr> <tr> <td colspan="3" style="border-bottom:1px inset #C0D9D9;padding-top:7px;"></td> </tr> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp:Repeater> <p style="margin-left:50px;"> <p style="margin:0 auto; margin-top:50px;border:1px solid #fff;font-size:16px;font-family:"microsoft yahei","宋体";"> <a><p style="border:1px solid #000; width:60px; float:left; margin:5px;text-align:center;"><a style="color:#000">共<asp:Label runat ="server" ID="zong"> </asp:Label>页</a></p></a> <a><p style="border:1px solid #000; width:60px; float:left;margin:5px;text-align:center;"><a style="color:#000">第<asp:Label runat ="server" ID="dangqian"> </asp:Label>页</a></p></a> <a><p style="border:1px solid #000; width:40px; float:left;margin:5px;text-align:center;"> <a style="color:#000"><asp:hyperlink id="first" runat="server" style="color:#000">首页</asp:hyperlink></a></p></a> <a><p style="border:1px solid #000; width:60px; float:left;margin:5px;text-align:center;"><a style="color:#000"><asp:hyperlink id="lnkPrev" runat="server" style="color:#000">上一页</asp:hyperlink></a></p></a> <a><p style="border:1px solid #000; width:60px; float:left;margin:5px;text-align:center;"><a style="color:#000"><asp:hyperlink id="lnkNext" runat="server" style="color:#000">下一页</asp:hyperlink></a></p></a> <a><p style="border:1px solid #000; width:40px; float:left;margin:5px;text-align:center;"> <a style="color:#000"><asp:hyperlink id="end" runat="server" style="color:#000">尾页</asp:hyperlink></a></p></a> </p> </p> </body>
Backend code:
protected void Page_Load(object sender, EventArgs e) { if(!Page.IsPostBack) { getUsers(); } } private void getUsers() { List<Users1> list = new AdminManager().QueryUsers(); PagedDataSource pag = new PagedDataSource(); pag.AllowPaging = true;// 设置允许分页 pag.PageSize = 10; // 每页显示为3行 pag.DataSource = list; // 模板绑定数据源 zong.Text = pag.PageCount.ToString(); // 显示总共页数 int CurrentPage; // 请求页码为不为null设置当前页,否则为第一页 if (Request.QueryString["Page"] != null) { CurrentPage = Convert.ToInt32(Request.QueryString["Page"]); } else { CurrentPage = 1; } if (Request.QueryString["PageSize"] != null) { pag.PageSize = Convert.ToInt32(Request.QueryString["PageSize"]); } else { pag.PageSize = 10; } pag.CurrentPageIndex = CurrentPage - 1; // 当前页所引为页码-1 dangqian.Text = CurrentPage.ToString(); // 当前页 if (!pag.IsFirstPage) { // Request.CurrentExecutionFilePath为当前请求虚拟路径 lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurrentPage - 1); } // 如果不是最后一页,通过参数Page设置下一页为当前页+1,否则不显示连接 if (!pag.IsLastPage) { // Request.CurrentExecutionFilePath为当前请求虚拟路径 lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurrentPage + 1); } //首页 first.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(1); //尾页 end.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + pag.PageCount.ToString(); if (Convert.ToInt32(HttpContext.Current.Request["page"]) > pag.PageCount) { first.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(1); } this.Repeater1.DataSource = pag; this.Repeater1.DataBind(); }
If you don’t need paging, you can execute the following code:
protected void Page_Load(object sender, EventArgs e) { if(!Page.IsPostBack) { getUsers(); } } private void getUsers() { List<Users1> list = new AdminManager().QueryUsers(); this.Repeater1.DataSource = list ; this.Repeater1.DataBind(); }
[Related recommendations]
2. ASP Tutorial
3. Li Yanhui ASP Basic Video Tutorial
The above is the detailed content of Detailed code explanation about repeater and paging effects (ASP). For more information, please follow other related articles on the PHP Chinese website!

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

.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.

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.

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 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.

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

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 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.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 English version
Recommended: Win version, supports code prompts!

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

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),

Dreamweaver CS6
Visual web development tools
