<script runat = "server" >
Const Record_Per_Page As Short = 5 '定义每一页显示的记录数
Private Script_Name As String
Sub Page_Load ( Source As Object , e As EventArgs )
Script_Name = GetPageName ( )
'第二种方式来分页显示数据
ShowRecords ( )
End Sub
'得到起始浏览超链接字符串
Function GetPageName ( ) As String
Dim Str As String
Dim Pos As Short
Str = Request.ServerVariables ( "Script_Name" ).Trim ( )
Pos = Str.LastIndexOf ( "/" )
If Pos >= 0 Then
Return Str.SubString ( Pos + 1 )
Else
Return Str
End If
End Function
Private Sub ShowRecords ( )
Dim strConn As String '定义数据连接字符串
Dim SQL As String '定义SQL语句
Dim odConn As OleDbConnection
Dim odAdapt As OleDbDataAdapter
Dim DS As DataSet '创建DataSet对象
Dim DT As DataTable '创建DataTable对象
Dim nRecCount As Integer '保存记录总数
Dim nPageCount As Integer '保存总共的数据页面数目
Dim nPage As Integer '存放要浏览当前数据页面号
Dim nStart As Integer '存放当前页面的起始记录序号
Dim nEnd As Integer '存放当前页面的终止记录序号
Dim nPageEnd As Integer '存储当前页面的最后一面的序号
Dim i As Integer
'确认要浏览的页面序号
nPage = Convert.ToInt32 ( Request.QueryString ( "Page" ) )
SQL = "SELECT * FROM tblItem "
Dim nStart As Integer '存放当前页面的起始记录序号
Dim nEnd As Integer '存放当前页面的终止记录序号
Dim i As Integer
nStart = Record_Per_Page * ( nPage - 1 )
nEnd = nStart + Record_Per_Page - 1
If nEnd > nRecCount - 1 Then
nEnd = nRecCount - 1
End If
'在屏幕中输出记录
For i = nStart To nEnd
Response.Write ( DT.Rows ( i ) ( "ItemName" ) & " <br > " )
Next
<% @ Page Language = "VB" %>
<% @ Import Namespace = "System.Data" %>
<% @ Import Namespace = "System.Data.OleDb" %>
<script runat = "server" >
Const Record_Per_Page As Short = 5 '定义每一页显示的记录数
Private Script_Name As String
Sub Page_Load ( Source As Object , e As EventArgs )
Script_Name = GetPageName ( )
'第一种方式来分页显示数据
ShowRecords ( )
End Sub
'得到起始浏览超链接字符串
Function GetPageName ( ) As String
Dim Str As String
Dim Pos As Short
Str = Request.ServerVariables ( "Script_Name" ).Trim ( )
Pos = Str.LastIndexOf ( "/" )
If Pos >= 0 Then
Return Str.SubString ( Pos + 1 )
Else
Return Str
End If
End Function
'此函数的功能是分页显示数据库中的记录
Private Sub ShowRecords ( )
Dim strConn As String '定义数据连接字符串
Dim SQL As String '定义SQL语句
Dim odConn As OleDbConnection
Dim odAdapt As OleDbDataAdapter
Dim DS As DataSet '创建DataSet对象
Dim DT As DataTable '创建DataTable对象
Dim nRecCount As Integer '保存记录总数
Dim nPageCount As Integer '保存总共的数据页面数目
Dim nPage As Integer '存放要浏览当前数据页面号
Dim nStart As Integer '存放当前页面的起始记录序号
Dim nEnd As Integer '存放当前页面的终止记录序号
Dim i As Integer
'创建数据连接字符串
strConn = " Provider = Microsoft.Jet.OLEDB.4.0 ; " & _
" Data Source = " & Server.MapPath ( "data.mdb" ) & " ; " & _
" User ID = ; Password = ; "
Try
'得到数据记录总数
odConn = New OleDbConnection ( strConn )
odAdapt = New OleDbDataAdapter ( SQL , odConn )
DS = New DataSet
odAdapt.Fill ( DS )
DT = DS.Tables ( 0 )
nRecCount = DT.Rows.Count
Catch e As Exception
Response.Write("错误信息: <b>" & e.Message & "</b><p>")
nRecCount = 0
End Try
'判断是否存在数据记录
If nRecCount > 0 Then
' 确定数据记录要显示的页面数
nPageCount = nRecCount \ Record_Per_Page
If nRecCount Mod Record_Per_Page > 0 Then
nPageCount += 1
End If
'确认浏览命令中的页面参数是否越界,如果越界则重置页面序号
If nPage < 1 Then
nPage = 1
End If
If nPage > nPageCount Then
nPage = nPageCount
End If
Function GetPageName ( ) As String
Dim Str As String
Dim Pos As Short
Str = Request.ServerVariables ( "Script_Name" ).Trim ( )
Pos = Str.LastIndexOf ( "/" )
If Pos >= 0 Then
Return Str.SubString ( Pos + 1 )
Else
Return Str
End If
End Function
<% @ Page Language = "VB" %>
<% @ Import Namespace = "System.Data" %>
<% @ Import Namespace = "System.Data.OleDb" %>
<script runat = "server" >
Dim strConn As String '定义数据连接字符串
Dim SQL As String '定义SQL语句
Dim odConn As OleDbConnection
Dim odAdapt As OleDbDataAdapter
Dim DS As DataSet '创建DataSet对象
Dim DT As DataTable '创建DataTable对象
Dim nStart As Integer '存放当前页面的起始记录序号
Dim nEnd As Integer '存放当前页面的终止记录序号
Dim i As Integer
Const Record_Per_Page As Short = 5 '定义每一页显示的记录数
Dim nPageCount As Integer '保存总共的数据页面数目
Dim nPage As Integer '存放要浏览当前数据页面号
nPageCount = nRecCount \ Record_Per_Page
If nRecCount Mod Record_Per_Page > 0 Then
nPageCount += 1
End If
'确认浏览命令中的页面参数是否越界,如果越界则重置页面序号
If nPage < 1 Then
nPage = 1
End If
If nPage > nPageCount Then
nPage = nPageCount
End If
Sub DropDownList2_SelectedIndexChanged(sender As Object, e As EventArgs)
DropDownList1.SelectedIndex=0
BindList(DropDownList1.SelectedIndex+1)
PageListItem()
ShowWhatButton()
End Sub
'''''''show linkbutton ( next or previous )'''''''''''''''''''''''''''''''''''''''''''''''''''
Sub LinkButton1_Click(sender As Object, e As EventArgs)
DropDownList1.SelectedIndex=0
Bindlist(DropDownList1.SelectedIndex+1)
ShowWhatButton()
End Sub
Sub LinkButton2_Click_1(sender As Object, e As EventArgs)
Sub LinkButton3_Click_1(sender As Object, e As EventArgs)
DropDownList1.SelectedIndex=DropDownList1.SelectedIndex-1
Bindlist(DropDownList1.SelectedIndex+1)
ShowWhatButton()
End Sub
Sub LinkButton4_Click_1(sender As Object, e As EventArgs)
DropDownList1.SelectedIndex=Label2.text-1
Bindlist(DropDownList1.SelectedIndex+1)
ShowWhatButton()
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub ShowWhatButton()
IF DropDownList1.SelectedIndex=0 THEN
' Insert page code here
'
'''''''''''''''''''''''datalist pagination code''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub BindList(PageNo as Integer)
Dim MyTable As DataTable=CreateDataSet("select * from YongHu", "mm", "YongHu").tables("YongHu")
Dim TotalRecord=MyTable.rows.count
Label1.text=TotalRecord
dim TotalPage as Integer
IF TotalRecord < DropDownList2.SelectedItem.Value THEN
TotalPage=1
ELSE
IF TotalRecord Mod DropDownList2.SelectedItem.Value <>0 THEN
'''''''''''''''''insert DropDownlist pageRecord'''''''''''''''''''''''''
Sub PageListItem()
Dim I as Integer
DropDownList1.Items.Clear()
For I=0 To label2.text-1
DropDownList1.Items.add(i+1)
next
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''change PageRecord'''''''''''''''''''''
Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs)
Bindlist(DropDownList1.SelectedIndex+1)
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
转贴
<%@ 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
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