Repeater paging and repeater paging controls

Source: Internet
Author: User

Repeater paging and repeater paging controls

1. place two labels (lbl) on the page to display the current page and the total page number respectively, and then place four linkbuttons to indicate the home page, next page, previous page, and last page respectively.

2. Create a paging method by yourself:

Public void contrlRepeater ()
{
String SQL = "select * from dbo. tb_Reply where ReplyID =" + this. Request. QueryString ["lyid"]. ToString () + "";
DataTable dt = db. GetT (SQL );
PagedDataSource PPS = new PagedDataSource ();
PPS. DataSource = dt. DefaultView;
PPS. AllowPaging = true; // allow pagination
PPS. PageSize = 2; // number of records per page
PPS. CurrentPageIndex = Convert. ToInt32 (this. labPage. Text)-1;
Repeater1.DataSource = PPS; // bind the data source to the paging class
LabCountPage. Text = PPS. PageCount. ToString ();
LabPage. Text = (maid. CurrentPageIndex + 1). ToString ();
This. lbtnpritPage. Enabled = true;
This. lbtnFirstPage. Enabled = true;
This. lbtnNextPage. Enabled = true;
This. lbtnDownPage. Enabled = true;
If (PPS. CurrentPageIndex <1)
{
This. lbtnpritPage. Enabled = false;
This. lbtnFirstPage. Enabled = false;
}
If (maid. CurrentPageIndex = maid. PageCount-1)
{
This. lbtnNextPage. Enabled = false;
This. lbtnDownPage. Enabled = false;
}
Repeater1.DataBind ();
}

 

Iii. LOAD event call

If (! IsPostBack) // If the page is not resend
{
This. labPage. Text = "1 ";
ContrlRepeater ();
}

4. Write the Click Event of the four buttons

Protected void lbtnpritPage_Click (object sender, EventArgs e)
{
This. labPage. Text = Convert. ToString (Convert. ToInt32 (labPage. Text)-1 );
This. contrlRepeater ();
}

Protected void lbtnFirstPage_Click (object sender, EventArgs e)
{
This. labPage. Text = "1 ";
This. contrlRepeater ();
}

Protected void lbtnDownPage_Click (object sender, EventArgs e)
{
This. labPage. Text = this. LabCountPage. Text;
This. contrlRepeater ();
}

Protected void lbtnNextPage_Click (object sender, EventArgs e)
{
This. labPage. Text = Convert. ToString (Convert. ToInt32 (labPage. Text) + 1 );
This. contrlRepeater ();
}


How to Implement paging with repeater

Repeater if you want to implement paging, you need to write an SQL statement to check the paging data and calculate the page number. This method is too troublesome.
You can use ListView + DataPager to implement it. DataPager provides many paging styles. If not, you can rewrite datapagerjavasprerender. I generally rewrite pages to do this.

Repeater Paging

It seems that there is no problem in the Paging function.

Every time you click the button. Page_Load, It will be executed. So add! Try ispostback.
Protected void Page_Load (object sender, EventArgs e)
{
If (! Ispostback)
Paging ();
}

Supplement-SQL statement. If no paging is written, add it.
Select top 10 * from lyb where lyb_id not in (select top 1*10 lyb_id from lyb order by lyb_id) order by lyb_id
The two numbers (1 and 10) must be processed on the page.
1 is your page number, and 10 is the number of records to be displayed on each page.
The reason for writing (1*10) is to help you understand the relationship. You need to use it after page processing. There cannot be a multiplication character "*" in the SQL text "*".

Related Article

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.