Table Name: chinastates
Control: Repeater
Query Code DA :
public class CHINASTATESDA
{
Private Dataclassesdatacontext Context; Building LINQ
Public Chinastatesda ()
{
Context = new Dataclassesdatacontext ();
}
Public list<chinastates> Select (int nowye,int numbers)
Enter the current page, page data bar number, query database information
{
Return Context.ChinaStates.Skip ((nowye-1) *numbers). Take (Numbers). ToList ();
// . Skip is how many data queries are skipped. Take to query the first few data
}
public int Select ()//query database how many data
{
return Context.ChinaStates.Count ();
}
}
Cs Code ,;
public partial class _default:system.web.ui.page
{
protected void Page_Load (object sender, EventArgs e)//Run interface
{
if (! IsPostBack)
{
Bindchinadata (1,5); Binding Data ①
int count = new Chinastatesda (). Select (); Get how many data in a database
Yeshu = (int) (math.ceiling (count/5.0));
Calculate Database page 5 data, how many pages can be displayed
}
}
private static int Yeshu; Build total number of pages type static indicates that this value is always there.
private void Bindchinadata (int nowye,int numbers)//bind data function ①
Nowye Now page, numbers the number of data per page
{
Repeater1.datasource = new Chinastatesda (). Select (nowye,numbers);
Repeater1.databind ();
TextBox1.Text = Nowye. ToString ();
Call the query function in da Select to bind to Repeater
TextBox1.Text Current number of pages
}
protected void Button3_Click (object sender, EventArgs e)//Next page
{
int nowye = Int. Parse (TextBox1.Text); Build the current page Nowye and assign values
if (yeshu!= nowye)
Determines whether the current page Nowye equals the total number of pages Yeshu, not equal to the new binding repeater
{
Bindchinadata (Nowye + 1, 5);
}
}
protected void button2_click (object sender, EventArgs e)//prev
{
int nowye = Int. Parse (TextBox1.Text); Build the current page Nowye and assign values
if (nowye! = 1)
Determines whether the current page nowye is equal to the first page and does not equal the new binding repeater
{
Bindchinadata (nowye-1, 5);
}
}
protected void Button5_click (object sender, EventArgs e)//Jump page
{
int nowye = Int. Parse (TextBox1.Text); Build the current page Nowye and assign values
if (nowye>0 && Nowye<=yeshu)//judgment greater than 0 less than the total number of pages from the new binding repeater
{
Bindchinadata (Nowye, 5);
}
}
protected void Button1_Click (object sender, EventArgs e)//home
{
Bindchinadata (1, 5);
}
protected void Button4_Click (object sender, EventArgs e)//Last
{
Bindchinadata (Yeshu, 5);
}
}
Repeater pagination Display Data