OpenDatabase()
BindGrid()
End Sub
Sub MyDataGrid_Page(ByVal sender As Object, ByVal e As DataGridPageChangedEventArgs)
Dim startIndex As Integer
startIndex = MyDataGrid.CurrentPageIndex * MyDataGrid.PageSize
MyDataGrid.CurrentPageIndex = e.NewPageIndex
BindGrid()
ShowStats()
End Sub
Sub BindGrid()
Dim myConnection As SqlConnection = cn
Dim ds As DataSet = New DataSet()
Dim adapter As SqlDataAdapter = New SqlDataAdapter("Select * from Orders", myConnection)
adapter.Fill(ds, "Orders")
MyDataGrid.DataSource = ds.Tables("Orders").DefaultView
MyDataGrid.DataBind()
ShowStats()
End Sub
Sub PagerButtonClick(ByVal sender As Object, ByVal e As EventArgs)
'used by external paging UI
Dim arg As String = sender.CommandArgument
Select Case arg
Case "next"
If (MyDataGrid.CurrentPageIndex < (MyDataGrid.PageCount - 1)) Then
MyDataGrid.CurrentPageIndex = 1
End If
Case "prev"
If (MyDataGrid.CurrentPageIndex > 0) Then
MyDataGrid.CurrentPageIndex -= 1
End If
Case "last"
MyDataGrid.CurrentPageIndex = (MyDataGrid.PageCount - 1)
Case Else
'page number
MyDataGrid.CurrentPageIndex = System.Convert.ToInt32(arg)
End Select
BindGrid()
ShowStats()
End Sub
Sub ShowStats()
lblCurrentIndex.Text = "第 " (MyDataGrid.CurrentPageIndex 1).ToString() " 页"
lblPageCount.Text = "总共 " MyDataGrid.PageCount.ToString() " 页"
End Sub
Public cn As New SqlClient.SqlConnection()
Public Sub OpenDatabase()
cn.ConnectionString = "Server=.;Database=NorthWind;User Id=sa;Password=;"
cn.Open()
End Sub
End Class
文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!



