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 對象的相關(guān)屬性賦值
Dim objPds As PagedDataSource = New PagedDataSource()
objPds.DataSource = ds.Tables(0).DefaultView
objPds.AllowPaging = True
objPds.PageSize = 10
'當(dāng)前頁面從Page查詢參數(shù)獲取
If (Request.QueryString("Page") <> "") Then
CurPage = Convert.ToInt32(Request.QueryString("Page"))
Else
CurPage = 1
End If
objPds.CurrentPageIndex = CurPage - 1
lblCurrentPage.Text = "當(dāng)前為第: " & 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的數(shù)據(jù)源就是這
Repeater1.DataBind()
End Sub
'其中l(wèi)nknext、lnkprev、lnkfirst、lnklast是HyperLink控件,lblcurrentpage、lblcout是label控件