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 );
}
}