|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
ASP在国内异常流行,因为国内大多使用的是盗版的Windows和盗版的SQLServer,而ASP+COM+SQLServer实际上也是一种不错的搭配,其性能也不输于PHP+MYSQL,特别是Windows系统和SQLServer都有图形界面,比APACHE和MYSQL易于维护,因此对于不重视知识产权的国家来说也是一种不错的选择。Pagingthrougharecordset
byDanielAdrian
Skilllevel:Beginner
Firstposted:Monday,October09,2000
Pagingthrougharecordset
WhenIwanttodevelopanapplicationwithalotofrecordstoshow,ImakepagessoIcaneasilynavigate
throughthedatabaseandmakethepagelookgoodandloadquickly.
Thiscanbedoneveryeasily.Shallwestart?
Takealookatthesenextlinesofcode:
IfRequest.QueryString("Page")=""Then
Page=1
Else
Page=Request.QueryString("Page")
EndIf
recordsToShow=20
n=0
TheselinesofcodearesayingifthevalueofRequest.QueryString("Page")iswithoutanyvaluethenpage
=1elsepagegetsthepagetheuserrequested.Recordstoshowisthenumberoflinesineachpage.
Nisnumberofrecordsprinted.
Nowletsputitintoaction:
objrs.PageSize=recordsToShow
(objrsisADODB.RecordsetObject)
Inpagesizewearetellingtherecordsetthateverypagewillhave20recordsbecauserecordstoshowis20.
Nowlet’spulloutsomerecords:
Dountilobjrs.EOF
ifn=recordsToShowthen
exitdo
endif
writewhatthatyouwanthere
n=n+1
loop
Nowwearewritingdateforthedatabaseandeverytimethatwearerepeatingtheloopwecheckifwedone
it20timessomewhenit’s20wewillstoptheloop.
Nowlet’swritethenavigation:
ifPage1then
Response.Write"<ahref=pagename.asp?currentPage="¤tPage-1&">"
endif
Response.Write"<<Back"
ifPage1then
Response.Write"</a>"
endif
-------------------------
ForintCount=1toobjRs.PageCount
IfintCount=1then
Response.Write"|"
EndIf
Ifcint(intCount)=cint(Page)then
Response.Write"<fontcolor=darkblue><b>"&intCount&"</b></font>|"
Else
Response.Write"<ahref=pagename.asp?currentPage="&intCount&""">"&intCount&"</a>|"
EndIf
Next
-------------------------
ifcint(page)=cint(objRs.PageCount)then
Response.Write"<ahref=pagename.asp?currentPage="¤tPage+1&">"
endif
Response.Write"Next>>"
ifcint(Page)=cint(objRs.PageCount)then
Response.Write"</a>"
endif
Firstwearecheckingifthecurrentpageisnot1soit’smorethenonesowecangoback.
Afterthisweneedtowriteallofthepagesintherecordset.
Nowweneedtocheckifwecandonext.
Thatisall!Yesit’sthateasy!
想法是和程序员的想法不一样的.至于为什么.大家去想一想.跟心理学有关的 |
|