(1)首先定义几个变量DimpageIndexAsInteger
DimpageSizeInteger=20
DimtotalPageDimtotalRecord(2)然后写显示页码的函数
SubxianShiYeMa()
DimleiBie1String=Request("leiBie")
pageIndex=Request("pageIndex")
Dimi
'第一次访问网页没有传进pageIndex的值,初始化pageIndex=1
IfRequest("pageIndex")=""Then
pageIndex=1
EndIf
IftotalPage<=10Then
i=1
DoWhilei<=totalPage
IfpageIndex=iThen
Response.Write("<aclass='juanZeng_xianShi_yeMa1'href='./xianShi.aspx?pageIndex="&pageIndex&"&leiBie="&leiBie1&"'>"&i&"</a>")
Else
Response.Write("<aclass='juanZeng_xianShi_yeMa2'href='./xianShi.aspx?pageIndex="&i&If
i=i+1
Loop
Else
'12345678910111213
IfpageIndex<=5Whilei<=totalPage
"<ahref='./xianShi.aspx?pageIndex="&pageIndex&"'><fontsize='5px'color='red'>"&i&"</font></a>")
"<ahref='./xianShi.aspx?pageIndex="&i&"'><fontsize='5px'color='blue'>"&i&ElseIfpageIndex>=totalPage-4Then
i=totalPage-9
Else
i=pageIndex-4
Whilei<=pageIndex+5
Sub
(3)取出数据的sql语句是
MysqL="select*from(selecttop"&pageSize&"*from(selecttop"&pageSize*pageIndex&"*fromjuanZengBiaowhere类别='"&Request("leiBie")&"'orderby发布时间desc)orderby发布时间asc)orderby发布时间desc"
(4)在pageLoad中写上
'---------------做分页显示--------------
'做分页,每次访问这个页面时都会把pageIndex传进来,
'Response.Write(40Mod20)'做测试的
'2120,4012,
Ifdr("zongShu")Mod20>=1Anddr("zongShu")>20Then
totalPage=dr("zongShu")\20+1
ElseIfdr(Mod20=0"zongShu")\20
Else
totalPage=1
If
Label8.Text=totalPage‘Label8为显示总页数的控件
Else
pageIndex=Request(If
Label7.Text=pageIndex‘Label7为显示当前页页码的控件
'--------------做分页显示---------------
'对pageIndex先做判断,使pageIndex的值不能小于1
IfpageIndex>1Then
pageIndex=pageIndex-1
Else
pageIndex=1
"leiBie")
Response.Write("<script>{window.location='./xianShi.aspx?pageIndex="&pageIndex&"'}</script>")
'对pageIndex先做判断,使pageIndex的值不能大于总页数
"pageIndex")>=totalPageThen
pageIndex=totalPage
Else
pageIndex=pageIndex+1
"leiBie")
Response.Write("'}</script>")
'Response.Redirect("./xianShi.aspx?pageIndex="&pageIndex&"&leiBie="&leiBie&"")
(7)再加一个输入框,加一个跳到该页的按钮,此按钮事件的代码:
pageIndex=TextBox1.Text‘textBox1为跳到该页的输入框
IfTextBox1.Text<>AndpageIndex>totalPageThen
Label9.Visible=TrueExit'最后设置为不可见
Label9.Visible=False(8)显示页码的相关css
a.juanZeng_xianShi_yeMa1
{
color:#D22E46;
margin-left:5px;
font-size:20px;
padding-left:10px;
padding-right:height:15px;
border:1pxsolidlightgrey;
}
a.juanZeng_xianShi_yeMa2
{
lightgrey;
15px;
}