Simple use of AspNetPager

Source: Internet
Author: User
Tags connectionstrings
As a paging tool, AspNetPager is often used to bind data controls, such as DataGrid and Repeater.
Here, we will briefly describe how to bind the Repeater control. The binding methods for other controls are similar:

'Global variable I is used to read the number of records in the dataset (Note: One read is enough)
Dim I As New Integer

Protected Sub Page_Load (ByVal sender As Object, ByVal e As System. EventArgs) Handles Me. Load

If I = 0 Then
Con = New SqlConnection (ConfigurationManager. ConnectionStrings ("NEWS_ConnectionString"). ConnectionString)
Con. Open ()
Cmd = New SqlCommand ()
Cmd. Connection = con
Cmd. CommandText = "select count (*) from XWNRB"

'Aspnetpager control visible
Me. AspNetPager1.Visible = True

'Aspnetpager control displays 10 records per page
Me. AspNetPager1.PageSize = 10

'Aspnetpager control records the total number of records
Me. AspNetPager1.RecordCount = Convert. ToInt32 (cmd. ExecuteScalar ())

'Aspnetpager Control Data Binding
Me. SHOW_DATA_LIST ()
I = I + 1
Con. Close ()
End If

End Sub

Protected Sub SHOW_DATA_LIST ()

Con = New SqlConnection (ConfigurationManager. ConnectionStrings ("NEWS_ConnectionString"). ConnectionString)
SQL _Text = "select * from XWNRB where"
Da = New SqlDataAdapter (SQL _Text, con)
Dim ds As New Data. DataSet

'The first parameter is the stored data set ds.
'The second parameter is the sequence number of the stored start record.
'The third parameter is the number of records stored per page
'The fourth parameter is a specific table in the stored data set ds.
Da. Fill (ds, Me. AspNetPager1.PageSize * (Me. AspNetPager1.CurrentPageIndex-1), Me. AspNetPager1.PageSize, "NEWS_LIST ")

'Actually bound
Me. Repeater2.DataSource = ds. Tables ("NEWS_LIST"). DefaultView
Me. Repeater2.DataBind ()

End Sub

'That is, this event is triggered every time you click a new page, or when you click Pre, Next, Last...
Protected Sub AspNetPager1_PageChanged (ByVal src As Object, ByVal e As Wuqi. Webdiyer. PageChangedEventArgs) Handles AspNetPager1.PageChanged

'Update the current page number sequence
Me. AspNetPager1.CurrentPageIndex = e. NewPageIndex
'Bind after update
Me. SHOW_DATA_LIST ()

End Sub


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.