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 "*".