Home Backend Development C#.Net Tutorial Detailed code explanation about repeater and paging effects (ASP)

Detailed code explanation about repeater and paging effects (ASP)

May 05, 2017 pm 01:41 PM
asp repeater Pagination

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>
Copy after login

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();
 }
Copy after login

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();
}
Copy after login

[Related recommendations]

1. ASP Free Video Tutorial

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!

Statement of this Website
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

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 Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP development: How to implement table data sorting and paging functions PHP development: How to implement table data sorting and paging functions Sep 20, 2023 am 11:28 AM

PHP development: How to implement table data sorting and paging functions In web development, processing large amounts of data is a common task. For tables that need to display a large amount of data, it is usually necessary to implement data sorting and paging functions to provide a good user experience and optimize system performance. This article will introduce how to use PHP to implement the sorting and paging functions of table data, and give specific code examples. The sorting function implements the sorting function in the table, allowing users to sort in ascending or descending order according to different fields. The following is an implementation form

How to create custom pagination in CakePHP? How to create custom pagination in CakePHP? Jun 04, 2023 am 08:32 AM

CakePHP is a powerful PHP framework that provides developers with many useful tools and features. One of them is pagination, which helps us divide large amounts of data into several pages, making browsing and manipulation easier. By default, CakePHP provides some basic pagination methods, but sometimes you may need to create some custom pagination methods. This article will show you how to create custom pagination in CakePHP. Step 1: Create a custom pagination class First, we need to create a custom pagination class. this

Using JavaScript to implement paging display of table data Using JavaScript to implement paging display of table data Jun 16, 2023 am 10:00 AM

As data continues to grow, tabular display becomes more difficult. Most of the time, the amount of data in a table is so large that it becomes slow to load and users need to constantly browse the page to find the data they want. This article will introduce how to use JavaScript to realize paginated display of table data, making it easier for users to find the data they want. 1. Dynamically create tables. In order to make the paging function more controllable, tables need to be created dynamically. In the HTML page, add a table element similar to the one below.

How to use JavaScript to implement table paging function? How to use JavaScript to implement table paging function? Oct 20, 2023 pm 06:19 PM

How to use JavaScript to implement table paging function? With the development of the Internet, more and more websites use tables to display data. In some cases where the amount of data is large, the data needs to be displayed in pages to improve user experience. This article will introduce how to use JavaScript to implement table paging function and provide specific code examples. 1. HTML structure First, we need to prepare an HTML structure to host tables and paging buttons. We can use &lt;tab

Detailed explanation of the principle of MyBatis paging plug-in Detailed explanation of the principle of MyBatis paging plug-in Feb 22, 2024 pm 03:42 PM

MyBatis is an excellent persistence layer framework. It supports database operations based on XML and annotations. It is simple and easy to use. It also provides a rich plug-in mechanism. Among them, the paging plug-in is one of the more frequently used plug-ins. This article will delve into the principles of the MyBatis paging plug-in and illustrate it with specific code examples. 1. Paging plug-in principle MyBatis itself does not provide native paging function, but you can use plug-ins to implement paging queries. The principle of paging plug-in is mainly to intercept MyBatis

How to use Layui to develop a data display page with paging function How to use Layui to develop a data display page with paging function Oct 24, 2023 pm 01:10 PM

How to use Layui to develop a data display page with paging function Layui is a lightweight front-end UI framework that provides simple and beautiful interface components and a rich interactive experience. During development, we often encounter situations where we need to display large amounts of data and perform paging. The following is an example of a data display page with paging function developed using Layui. First, we need to introduce Layui related files and dependencies. Add the following code to the &lt;head&gt; tag of the html page

Vue component practice: paging component development Vue component practice: paging component development Nov 24, 2023 am 08:56 AM

Vue component practice: Introduction to paging component development In web applications, the paging function is an essential component. A good paging component should be simple and clear in presentation, rich in functions, and easy to integrate and use. In this article, we will introduce how to use the Vue.js framework to develop a highly customizable paging component. We will explain in detail how to develop using Vue components through code examples. Technology stack Vue.js2.xJavaScript (ES6) HTML5 and CSS3 development environment

How to implement paging function in Vue technology development How to implement paging function in Vue technology development Oct 09, 2023 am 09:06 AM

Vue is a popular JavaScript framework for building user interfaces. In the development of Vue technology, implementing paging function is a common requirement. This article will introduce how to use Vue to implement paging function and provide specific code examples. Before we start, we need to prepare some basic knowledge in advance. First, we need to understand the basic concepts and syntax of Vue. Secondly, we need to know how to use Vue components to build our application. Before we start, we need to install a paging plug-in in the Vue project,

See all articles