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