Inherits System.Web.UI.Page
Dim scon As New SqlConnection("server=localhost;database=northwind;uid=sa;pwd=sa")
Dim sDA As SqlDataAdapter
Dim ds As New Data.DataSet
Dim currentPage As Integer
Dim maxPage As Integer
Const rowCount As Integer = 3
Dim rowSum As Integer
Sub BindData()
Repeater1.DataSource = ds
Repeater1.DataBind()
lblIndex.Text = currentPage
End Sub
Sub readpage(ByVal n As Integer)
sDA = New SqlDataAdapter("select employeeid, lastname from employees order by employeeid", scon)
ds = New Data.DataSet
ds.Clear()
sDA.Fill(ds, (n - 1) * rowCount, rowCount, "employees")
End Sub
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
sDA = New SqlDataAdapter("select employeeid, lastname from employees order by employeeid", scon)
ds = New Data.DataSet
Try
sDA.Fill(ds, "employees")
rowSum = ds.Tables(0).Rows.Count
Catch ex As Exception
rowSum = 0
End Try
If rowSum = 0 Then Exit Sub
If rowSum Mod rowCount > 0 Then
maxPage = rowSum \ rowCount + 1
Else
maxPage = rowSum \ rowCount
End If
currentPage = 1
readpage(currentPage)
BindData()
lblTotal.Text = maxPage
btnStart.Enabled = False
btnBack.Enabled = False
End If
End Sub
Protected Sub btnStart_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnStart.Click
currentPage = 1
readpage(currentPage)
BindData()
btnStart.Enabled = False
btnBack.Enabled = False
btnGo.Enabled = True
btnEnd.Enabled = True
End Sub
Protected Sub btnBack_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnBack.Click
If lblIndex.Text > 2 Then
btnGo.Enabled = True
btnEnd.Enabled = True
Else
btnStart.Enabled = False
btnBack.Enabled = False
btnGo.Enabled = True
btnEnd.Enabled = True
End If
currentPage = lblIndex.Text - 1
readpage(currentPage)
BindData()
End Sub
Protected Sub btnGo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGo.Click
If lblIndex.Text < lblTotal.Text - 1 Then
btnStart.Enabled = True
btnBack.Enabled = True
Else
btnStart.Enabled = True
btnBack.Enabled = True
btnGo.Enabled = False
btnEnd.Enabled = False
End If
currentPage = lblIndex.Text + 1
readpage(currentPage)
BindData()
End Sub
Protected Sub btnEnd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnEnd.Click
currentPage = lblTotal.Text
readpage(currentPage)
BindData()
btnStart.Enabled = True
btnBack.Enabled = True
btnGo.Enabled = False
btnEnd.Enabled = False
End Sub
End Class