Paging Problems with repeater controls

Source: Internet
Author: User
Tags count tostring
Pagination | control | Problems before the time to do ASP is not short, but do asp.net I am a novice. A few days ago to do the project, encountered a problem, requiring more complex data format display, with a DataGrid is very difficult to achieve, and later used the Repeater control to achieve. But this brings up a new problem: How to page pagination? Repeater does not have a built-in paging capability. Later, I tried to write one, I was lucky to succeed. Hastily written on, certainly imperfect, which Master has any ideas please correct, very willing to communicate with you (zhoubin@mail.sdu.edu.cn)

Protected System.Web.UI.WebControls.Repeater Rptframework



private void Page_Load (object sender, System.EventArgs e)
{



Set up a dataset
(this part is omitted)

Rptframework.datasource = myDataSet;
Rptframework.databind ();

session["Page" = 1;





Hide all entries in the Repeater
int i = 0;

for (i = 0; i < RptFramework.Items.Count; i++)
{
Rptframework.items[i]. Visible = false;
}



Page size of the Repeater control
int intpagesize = 10;






Rptframework control's current page index (1 start)
int intcurrentpageindex = 0;



if (request.querystring["page"] = = NULL | | Convert.ToInt32 (request.querystring["page"]) = = 0)
{
session["Page" = 1;
}
Else
{
session["Page" = Convert.ToInt32 (request.querystring["page"));
}

Intcurrentpageindex = Convert.ToInt32 (session["page");



Previous Page button mask
if (Convert.ToInt32 (session["page"]) = = 1)
{
btnpre.enabled = false;
}



Current cursor index of the Rptframework control (1 start)
int intcurrentitemindex = 1;
Intcurrentitemindex = Intpagesize * (intCurrentPageIndex-1) + 1;



Next Page button mask
if ((Rptframework.items.count-intcurrentitemindex) < intpagesize)
{
btnnext.enabled = false;
}




Set the default view when a form is loaded
if (RptFramework.Items.Count > Intpagesize)
{
for (i = Intcurrentitemindex i < getmin (RptFramework.Items.Count, Intcurrentitemindex + intpagesize); i++)
{
RPTFRAMEWORK.ITEMS[I-1]. Visible = true;
}


}



}




Take the smaller value of two values, but do not change the original value size
private int Getmin (int a, int b)
{
int C;
if (a > B)
{
c = b;
}
Else
{
c = A;
}
return C;
}



Click on the previous page button
private void Btnpre_click (object sender, System.EventArgs e)
{

int intprepageindex = 2;

if (Convert.ToInt32 (session["page"))!= 1)
{
Intprepageindex = Convert.ToInt32 (session["page")-1;
}
Else
{
Intprepageindex = 1;
}

Response.Redirect ("jggk.aspx?page=" + intprepageindex.tostring ());
}



Click on the next page button
private void Btnnext_click (object sender, System.EventArgs e)
{
int intnextpageindex = Convert.ToInt32 (session["page"]) + 1;
Response.Redirect ("jggk.aspx?page=" + intnextpageindex.tostring ());
}



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.