Repeater sub-page

Source: Internet
Author: User

In fact, repeater paging is a very simple process, as long as you look carefully inside the logic, I believe you can do it!

To prepare the page footage :

1, the front page needs to place a Repeater to display the data you request to display.

2, a hidden domain lable is used to control the number of pages.

3, two picture buttons are used to achieve the click Switch page number.

Backstage :

1, data source, we use a DataTable, used to bind repeater.

2, paging control data source PagedDataSource, used to page fill.

Principle:

Sets the PagedDataSource display number, and then fills the data for the current page of PagedDataSource to Repeater, which results in a paging effect.

Front Code:

<div style= "height:1135px" > <div class= "Ngg" > news bulletins </div> <div class= "new" > <ul> <asp:repeater id= "Repeater1" runat= "Server" > <i                                    temtemplate> <li> <div class= "NEWBT" > <a href= "newstestshow.aspx?id=<% #Eval (" news_id ")%>" ><% #Eval ("News_title")%>&lt ;/a> </div> <div class= "NewTime" ><% #Eval ("                    New_time ")%></div> </li> </ItemTemplate> </asp:Repeater> </ul> </div> <div class= "Yeshu" &GT;&L t;! --prev Button--<asp:button id= "BTNP" runat= "Server" text= "previous" onclick= "Btnp_click"/><!--         One-page buttons--           <asp:button id= "BTNN" runat= "Server" text= "Next" onclick= "Btnn_click"/><!--hidden domain ID to control the current Pageddataso Urce pages-<asp:label visible= "false" id= "Lblcount" runat= "Server" text= "1" ></asp:label&            Gt </div> </div>

Background code:

public void Bind () {DataTable dt = new DataTable ();        SqlDataAdapter da = new SqlDataAdapter ("select * from New_news ORDER BY news_id Desc", connstr); Specifies the data source da.         Fill (DT);                 Instantiate pagerdatatable pageddatasource PDS = new PagedDataSource (); Binds a data PDS to the PDS. DataSource = dt.        DefaultView; Set up a paging PDS.        AllowPaging = true; Can be divided into several PDS.        PageSize = 8; Sets the default page PDS.        CurrentPageIndex = Convert.ToInt32 (lblCount.Text.ToString ())-1;         Repeater1.datasource=pds; If is greater than the current page if (PDS.            currentpageindex>=1) {btnp.enabled=true;        Btnn.enabled=true; }//If it is the last page, let the next page button not work if (PDS. Currentpageindex==pds.            PageCount-1) {btnn.enabled=false;        Btnp.enabled=true; }//If it is the first page if (PDS.            currentpageindex==0) {btnp.enabled=false;        Btnn.enabled=true; } REPEater1.    DataBind (); }//Next page event protected void Btnn_click (object sender, EventArgs e) {lblcount.text = (Convert.ToInt32 (Lblco Unt. Text.tostring ()) + 1).        ToString (); This.    Bind (); }//Previous page event protected void Btnp_click (object sender, EventArgs e) {lblcount.text = (Convert.ToInt32 (lblcou Nt. Text.tostring ())-1).        ToString (); This.    Bind (); }

Page_Load:

protected void Page_Load (object sender, EventArgs e)    {         Bind ();//Called when the form is loaded    }

Repeater sub-page

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.