下面是一个简单的ASP数字分页代码示例:
”’asp
<%
Dim PageSize, PageSizeOptions, PageIndex, PageCount, RecordCount, StartRecord, EndRecord
‘ 设置每页显示多少条记录
PageSize = 10
‘ 设置每页可选择的显示条数选项
‘ 例如:5,10,20,50
PageSizeOptions = “5,10,20,50”
‘ 获取当前页码
PageIndex = Request.QueryString(“pageIndex”)
If IsNumeric(PageIndex) Then
PageIndex = CInt(PageIndex)
Else
PageIndex = 1
End If
‘ 获取记录总数
RecordCount = 500 ‘ 假设总记录数为500
‘ 计算总共有多少页
PageCount = IIf(RecordCount Mod PageSize = 0, RecordCount / PageSize, Int(RecordCount / PageSize) + 1)
‘ 计算当前页的起始记录和结束记录
StartRecord = (PageIndex – 1) * PageSize + 1
EndRecord = IIf(StartRecord + PageSize – 1 > RecordCount, RecordCount, StartRecord + PageSize – 1)
‘ 输出每页可选择的显示条数选项
Response.Write(“<select onchange=""location.href='?pageIndex=" & PageIndex & "&pageSize=' + this.value"">”)
PageSizeArr = Split(PageSizeOptions, “,”)
For i = 0 To UBound(PageSizeArr)
If CInt(PageSizeArr(i)) = PageSize Then
Response.Write("<option selected>" & PageSizeArr(i) & "</option>")
Else
Response.Write("<option>" & PageSizeArr(i) & "</option>")
End If
Next
Response.Write(“</select>”)
‘ 输出当前页的起始记录和结束记录
Response.Write(“
“)
Response.Write(“第 ” & StartRecord & ” 条 – 第 ” & EndRecord & ” 条 / 共 ” & RecordCount & ” 条”)
‘ 输出分页链接
Response.Write(“
“)
If PageIndex > 1 Then
Response.Write("<a href=""?pageIndex=" & PageIndex - 1 & "&pageSize=" & PageSize & """>上一页</a> ")
End If
For i = 1 To PageCount
If i = PageIndex Then
Response.Write("<strong>" & i & "</strong> ")
Else
Response.Write("<a href=""?pageIndex=" & i & "&pageSize=" & PageSize & """>" & i & "</a> ")
End If
Next
If PageIndex < PageCount Then
Response.Write("<a href=""?pageIndex=" & PageIndex + 1 & "&pageSize=" & PageSize & """>下一页</a>")
End If
%>
以下是一个基于ASP的简单数字分页代码示例:
<%
' 当前页码
currentPage = Request.QueryString("page")
If IsEmpty(currentPage) Or Not IsNumeric(currentPage) Then
currentPage = 1
End If
' 每页记录数
pageSize = 10
' 总记录数
totalRecords = 100
' 计算总页数
totalPages = Int((totalRecords + pageSize - 1) / pageSize)
' 防止超出页数范围
If currentPage > totalPages Then
currentPage = totalPages
End If
If currentPage < 1 Then
currentPage = 1
End If
' 计算起止位置
startRecord = (currentPage - 1) * pageSize + 1
endRecord = currentPage * pageSize
If endRecord > totalRecords Then
endRecord = totalRecords
End If
%>
<table>
<%
For i = startRecord To endRecord
' 显示数据记录
Next
%>
</table>
<!-- 分页链接 -->
<div class="pagination">
<% If currentPage > 1 Then %>
<a href="?page=<%=currentPage-1%>">上一页</a>
<% End If %>
<% For i = 1 To totalPages %>
<% If currentPage = i Then %>
<span class="current"><%=i%></span>
<% Else %>
<a href="?page=<%=i%>"><%=i%></a>
<% End If %>
<% Next %>
<% If currentPage < totalPages Then %>
<a href="?page=<%=currentPage+1%>">下一页</a>
<% End If %>
</div>
此代码通过解析URL中的参数来处理分页逻辑,计算当前页码、总记录数、总页数、起止位置等,然后在HTML中输出数据和分页链接。其中, currentPage
表示当前页码, pageSize
表示每页记录数, totalRecords
表示总记录数, totalPages
表示总页数, startRecord
和 endRecord
表示当前页数据的起止位置。在HTML中,使用简单的循环和条件判断来输出分页链接和当前页的样式。你可以根据自己的实际需求进行修改和扩展。
发布者:luotuoemo,转转请注明出处:https://www.jintuiyun.com/116074.html