Introduction to repeater and paging effect in. NET,. netrepeater

Source: Internet
Author: User

Introduction to repeater and paging effect in. NET,. netrepeater

The Repeater control is a data binding container control that generates a list of items and can use templates to define the layout of items on the web page. When this page is running, the control repeats this layout for each item in the data source.

Use the repeater control with the template

To use the repeater control, you must create a template that defines the control content layout. A template can contain any combination of tags and controls. If no template is defined or the template does not contain any elements, the control is not displayed on the page when the application is running.

ItemTemplate: contains HTML elements and controls that must be presented once for each data item in the data source.
AlternatingItemTemplate: sets the format of alternate data items (including HTML elements and controls that must be presented once for each data item in the data source. Generally, you can use this template to create different appearances for alternate items. For example, you can specify a background color that is different from the color specified in ItemTemplate ).
SeparatorTemplate: format the delimiter (including the elements rendered between each entry .).
HeaderTemplate: Set the Header Format (including the text and controls displayed at the beginning of the list .).
FooterTemplate: set the format of the footer, including the text and controls displayed at the end of the list .).

 

 

The Repeater paging effect is as follows:

Front-end 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; "> User Name </span> <span style =" padding-left: 100px; "> registration time </span> <span style =" padding-left: 90px; "> access volume </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> <td colspan =" 3 "style =" border-bottom: 1px inset # C0D9D9; padding-top: 7px; "> </td> </tr> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp: repeater> <div style = "margin-left: 50px;"> <div style = "margin: 0 auto; margin-top: 50px; border: 1px solid # fff; font-size: 16px; font-family: "microsoft yahei", ""; "> <a> <div style =" border: 1px solid #000; width: 60px; float: left; margin: 5px; text-align: center; "> <a style =" color: #000 "> total <asp: label runat = "server" ID = "zong"> </asp: label> page </a> </div> </a> <div style = "border: 1px solid #000; width: 60px; float: left; margin: 5px; text-align: center; "> <a style =" color: #000 "> NO. <asp: label runat = "server" ID = "dangqian"> </asp: label> page </a> </div> </a> <div 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 "> homepage </asp: hyperlink> </a> </div> </a> <div 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"> previous page </asp: hyperlink> </a> </div> </a> <div 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 "> next page </asp: hyperlink> </a> </div> </a> <div 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"> last page </asp: hyperlink> </a> </div> </body>

Background 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; // set to allow pagination pag. pageSize = 10; // three pag lines are displayed on each page. dataSource = list; // The template binds the data source zong. text = pag. pageCount. toString (); // display the total number of pages int CurrentPage; // The Request page number is not null. Set the current page; otherwise, set it to the first page 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; // the current page is directed to the page number-1 dangqian. text = CurrentPage. toString (); // the current page if (! Pag. IsFirstPage) {// Request. CurrentExecutionFilePath is the virtual path of the current Request. lnkPrev. NavigateUrl = Request. CurrentExecutionFilePath + "? Page = "+ Convert. ToString (CurrentPage-1);} // if not the last Page, set the next Page to the current Page + 1 through the parameter Page. Otherwise, the connection if (! Pag. IsLastPage) {// Request. CurrentExecutionFilePath is the virtual path of the current Request. lnkNext. NavigateUrl = Request. CurrentExecutionFilePath + "? Page = "+ Convert. ToString (CurrentPage + 1);} // homepage 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 do not need paging, run 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();}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.