Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Dim objConn As OleDbConnection = New OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("App_Data\myweb.mdb") & ";Persist Security Info=False")
Dim strsql As String = "SELECT [wz_id],[wz_bt],[wz_hit],[wz_zz],mid(wz_nr,1,200) as sub_wz FROM [wenzhang] ORDER BY [wz_id] DESC"
Dim objCommand As OleDbDataAdapter = New OleDbDataAdapter(strsql, objConn)
Dim ds As DataSet = New DataSet()
Dim CurPage As Integer
objCommand.Fill(ds)
'对PagedDataSource 对象的相关属性赋值
Dim objPds As PagedDataSource = New PagedDataSource()
objPds.DataSource = ds.Tables(0).DefaultView
objPds.AllowPaging = True
objPds.PageSize = 10
'当前页面从Page查询参数获取
If (Request.QueryString("Page") <> "") Then
CurPage = Convert.ToInt32(Request.QueryString("Page"))
Else
CurPage = 1
End If
objPds.CurrentPageIndex = CurPage - 1
lblCurrentPage.Text = "当前为第: " & CurPage.ToString() & "页"
lblcount.Text = "共有" & objPds.PageCount & "页"
If objPds.IsFirstPage = False Then
lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath & "?Page=" & Convert.ToString(CurPage - 1)
lnkfirst.NavigateUrl = Request.CurrentExecutionFilePath & "?Page=" & "1"
End If
If objPds.IsLastPage = False Then
lnkNext.NavigateUrl = Request.CurrentExecutionFilePath & "?Page=" & Convert.ToString(CurPage + 1)
lnklast.NavigateUrl = Request.CurrentExecutionFilePath & "?Page=" & Convert.ToString(objPds.PageCount)
End If
'把PagedDataSource 对象赋给Repeater控件
Repeater1.DataSource = objPds 'repeater的数据源就是这
Repeater1.DataBind()
End Sub
'其中lnknext、lnkprev、lnkfirst、lnklast是HyperLink控件,lblcurrentpage、lblcout是label控件