Repeater displays data by PAGE and repeater displays data by PAGE

Source: Internet
Author: User

Repeater displays data by PAGE and repeater displays data by PAGE

 

Table Name: ChinaStates

Control: Repeater

Query codeDA:

Public class ChinaStatesDA

{

Private DataClassesDataContext Context; // construct a LINQ

Public ChinaStatesDA ()

{

Context = new DataClassesDataContext ();

}

 

Public List <ChinaStates> Select (int nowye, int numbers)

// Enter the number of data entries on the current page to query database information.

{

Return Context. ChinaStates. Skip (nowye-1) * numbers). Take (numbers). ToList ();

// How many data entries are skipped by the. Take command to query the first few data entries

}

 

Public int Select () // query the number of data records in the database

{

Return Context. ChinaStates. Count ();

}

}

CsCode,;

Public partial class _ Default: System. Web. UI. Page

{

Protected void Page_Load (object sender, EventArgs e) // run the interface

{

If (! IsPostBack)

{

Bindchinadata (); // bind data ①

Int count = new ChinaStatesDA (). Select (); // obtain the number of data records in the database.

Yeshu = (int) (Math. Ceiling (count/5.0 ));

// Calculate the number of pages on which five data entries are displayed on one page of the database

}

}

Private static int yeshu; // The type of the total number of pages to be built. static indicates that this value is always present.

 

Private void bindchinadata (int nowye, int numbers) // bind a data function ①

Nowye current page, number of data displayed on each page of numbers

{

Repeater1.DataSource = new ChinaStatesDA (). Select (nowye, numbers );

Repeater1.DataBind ();

TextBox1.Text = nowye. ToString ();

// Call the query function select in DA to bind to Repeater.

// The current page number of TextBox1.Text

}

 

 

 

Protected void Button3_Click (object sender, EventArgs e) // next page

{

Int nowye = int. Parse (TextBox1.Text); // construct the current page nowye and assign a value

If (yeshu! = Nowye)

// Determine whether the current page nowye is equal to the total page number yeshu, not the Repeater bound to the new page

{

Bindchinadata (nowye + 1, 5 );

}

}

Protected void Button2_Click (object sender, EventArgs e) // Previous Page

{

Int nowye = int. Parse (TextBox1.Text); // construct the current page nowye and assign a value

If (nowye! = 1)

// Determine whether the current page nowye is equal to the first page, not the Repeater bound to the new page

{

Bindchinadata (nowye-1, 5 );

}

}

Protected void Button5_Click (object sender, EventArgs e) // jump to the page

{

Int nowye = int. Parse (TextBox1.Text); // construct the current page nowye and assign a value

If (nowye> 0 & nowye <= yeshu) // determine whether the number of pages greater than 0 is smaller than the total number of pages and then bind the Repeater

{

Bindchinadata (nowye, 5 );

}

}

Protected void button#click (object sender, EventArgs e) // Home Page

{

Bindchinadata (1, 5 );

}

Protected void Button4_Click (object sender, EventArgs e) // last page

{

Bindchinadata (yeshu, 5 );

}

}

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.