由于DataList不支持内建的分页机制,因此,我们必须使用 SqlDataAdapter对象的Fill方法来实现分页,Fill方法主要用来增加或刷新DataSet的记录行。Fill方法已经被重载,我们这里选用四个参数的那个重载方法:DataSet, startRecord, maxRecords 和 TableName。
<%@ Import NameSpace="System.Data.OleDb" %>
<%@ Import NameSpace="System.Data" %>
<HTML>
<HEAD>
<script language="vb" runat="server">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
If Not Page.IsPostBack() Then
intPageSize.Text = "2"
intCurrIndex.Text = "0"
DataBind()
End If
End Sub
Private Sub DataBind()
Dim CnString As String
CnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
CnString = CnString + Server.MapPath("dataDB.mdb"))
Dim objConn As New OleDbConnection(CnString)
Dim objDA As New OleDbDataAdapter("SELECT * FROM Document ORDER BY CreateDate DESC", objConn)
Dim objDS As New DataSet()
If Not Page.IsPostBack() Then
objDA.Fill(objDS)
intRecordCount.Text = CStr(objDS.Tables(0).Rows.Count)
objDS = Nothing
objDS = New DataSet()
End If
objDA.Fill (objDS, CInt(intCurrIndex.Text), CInt(intPageSize.Text), "Document")
dList.DataSource = objDS.Tables(0).DefaultView
dList.DataBind()
objConn.Close()
PrintStatus()
End Sub
Public Sub ShowFirst(ByVal s As Object, ByVal e As EventArgs)
intCurrIndex.Text = "0"
DataBind()
End Sub
Public Sub ShowPrevious(ByVal s As Object, ByVal e As EventArgs)
intCurrIndex.Text = Cstr(Cint(intCurrIndex.Text) - CInt(intPageSize.Text))
If CInt(intCurrIndex.Text) < 0 Then
intCurrIndex.Text = "0"
End If
DataBind()
End Sub
Public Sub ShowNext(ByVal s As Object, ByVal e As EventArgs)
If CInt(intCurrIndex.Text) + 1 < CInt(intRecordCount.Text) Then
intCurrIndex.Text = CStr(CInt(intCurrIndex.Text) + CInt(intPageSize.Text))
End If
DataBind()
End Sub
Public Sub ShowLast(ByVal s As Object, ByVal e As EventArgs)
Dim tmpInt as Integer
tmpInt = CInt(intRecordCount.Text) Mod CInt(intPageSize.Text)
If tmpInt > 0 Then
intCurrIndex.Text = Cstr(CInt(intRecordCount.Text) - tmpInt)
Else
intCurrIndex.Text = Cstr(CInt(intRecordCount.Text) - CInt(intPageSize.Text))
End If
DataBind()
End Sub
Private Sub PrintStatus()
lblStatus.Text = "总记录数:<b>" & intRecordCount.Text
lblStatus.Text += "</b> 当前:<b> "
lblStatus.Text += CStr(CInt(CInt(intCurrIndex.Text) / CInt(intPageSize.Text)+1))
lblStatus.Text += "</b>/<b>"
If (CInt(intRecordCount.Text) Mod CInt(intPageSize.Text)) > 0 Then
lblStatus.Text += CStr(CInt(CInt(intRecordCount.Text) / CInt(intPageSize.Text)+1))
Else
lblStatus.Text += CStr(CInt(intRecordCount.Text) / CInt(intPageSize.Text))
End If
lblStatus.Text += "</b>"
End Sub
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<TABLE height="528" cellSpacing="0" cellPadding="0" width="244" border="0"
ms_2d_layout="TRUE">
<TBODY>
<TR vAlign="top">
<TD width="244" height="528">
<form id="Form1" method="post" runat="server">
<TABLE heig