Repeater pagination Display Data

Source: Internet
Author: User

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

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.