Repeater shows examples of data, with pagination

Source: Internet
Author: User
Pagination | data | show

Here's an example of repeater displaying data paging
I was in the time of the problem to mention the first I use DataReader to do the data source, is not, and then change the dataset
When setting up pagination, be sure to make sure the current page, if you set the current page to 1, then he will display the data from the second page, because its current page is starting from 0, and we show the current page is starting from 1
Before comparing to the total number of pages must also be set to the PS data source, I was first with PS. Currentpageindex==ps. PageCount-1 check whether on the last page, and then PS. Datasource=ds. tables["Authors"]. DefaultView set the data source, the result paging has been problematic.
Hehe, these several questions have done me half a day. Maybe I'm too much of a vegetable, but I haven't been studying. NET for long.

Using System;
Using System.Collections;
Using System.ComponentModel;
Using System.Data;
Using System.Drawing;
Using System.Web;
Using System.Web.SessionState;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.HtmlControls;
Using System.Data.SqlClient;
Namespace test
{
<summary>
Summary description of the Repeater.
</summary>
public class Repeater:System.Web.UI.Page
{
protected System.Web.UI.WebControls.Panel Panel1;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label lbcurpage;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Repeater Repeater1;

private void Page_Load (object sender, System.EventArgs e)
{
Place user code here to initialize page
if (!this. IsPostBack)
{
this.lbcurpage.text= "1";
This. Bindtorepeater ();
}
}
private void Bindtorepeater ()
{
SqlConnection con=new SqlConnection ("Data source=.; database=pubs;uid=sa;pwd=123a456b ");
SqlCommand cmd=new SqlCommand ("select * from authors", con);
Con. Open ();
SqlDataReader Dr;
Dr=cmd. ExecuteReader ();
SqlDataAdapter Da=new SqlDataAdapter ("select * from authors", con);
DataSet ds=new DataSet ();
Da. Fill (ds, "authors");
PagedDataSource ps=new PagedDataSource ();
Ps. Allowpaging=true;
Ps. pagesize=5;
This. Repeater1.datasource=ps;
Ps. Currentpageindex=convert.toint32 (This.lbCurPage.Text)-1;
Ps. Datasource=ds. tables["Authors"]. DefaultView;
This. Button1.enabled=true;
This. Button2.enabled=true;
if (Ps. currentpageindex==0)
{
This. Button1.enabled=false;
}
if (Ps. Currentpageindex==ps. PAGECOUNT-1)
{
This. Button2.enabled=false;
}
This. Repeater1.databind ();
}

Code generated #region the Web forms Designer
Override protected void OnInit (EventArgs e)
{
//
CodeGen: This call is required for the ASP.net Web forms Designer.
//
InitializeComponent ();
Base. OnInit (e);
}

<summary>
Designer supports required methods-do not use the Code editor to modify
The contents of this method.
</summary>
private void InitializeComponent ()
{
This. Button1.Click + = new System.EventHandler (this. Button1_Click);
This. Button2.click + = new System.EventHandler (this. button2_click);
This. Load + = new System.EventHandler (this. Page_Load);

}
#endregion

private void Button1_Click (object sender, System.EventArgs e)
{
This.lbcurpage.text=convert.tostring (Convert.ToInt32 (This.lbCurPage.Text)-1);
This. Bindtorepeater ();
}

private void Button2_Click (object sender, System.EventArgs e)
{
This.lbcurpage.text=convert.tostring (Convert.ToInt32 (This.lbCurPage.Text) +1);
This. Bindtorepeater ();
}
}
}



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.