波斯马BOSSMA Information Technology

管理模块中使用的分页程序(asp)

发布时间:2007年3月17日 / 分类:ASP.NET / 7,085 次浏览 / 评论

在web管理过程中,我们经常遇到这样的问题:
表单查询结果分页时做分页链接比较麻烦;在非第一页修改记录又后返回第一页。
这两个问题解决办法也很简单,现在做个总结:
以一个简单的新闻list管理举例:
功能:读取数据库记录,并实现分页,具有表单提交查询功能,在页面上能删除。

<%
'定义分页程序用全局变量
dim icount,page_total,page_no

'info1为提交标识,info2为表单提交信息
dim info1,info2
info1=trim(request.QueryString("info1"))
info2=trim(request.Querystring("info2"))
if info2=""then
info2=ProtectSQL(request.form("info2"))
end if
'获取当前页面Url
Dim tpath,tstring
page_no=request.QueryString("page_no")
tstring=Request.ServerVariables("QUERY_STRING")
if page_no>1 then
tstring=replace(tstring,"&action=del","")
else
if request("info2")<>"" then
tstring=replace(tstring,"&action=del","")
else
tstring=replace(tstring,"action=del","")
end if
end if
tpath="http://"Request.ServerVariables("HTTP_HOST") & Request.ServerVariables("SCRIPT_NAME")&"?"&tstring

select case info1
 case "del"
  call newsdel()
 case else
  call newslist()
end select

'查询数据库并生成页面代码省略
'只列出一条记录
"" then
response.write"&"
end if
end if
%>
action=del&newsid=<%=rs("news_id")%>">删除

'删除程序
sub newsdel()
id=trim(request.QueryString("id"))
strsql="delete from news where news_id="&id&""
conn.execute(strsql)
msgbox"删除成功!","GoUrl","http://"&tpath
end sub

'分页程序
public sub showpage()
if icount="" then
icount=0
end if
Dim query, a, x, temp
action = "http://" & Request.ServerVariables("HTTP_HOST") & Request.ServerVariables("SCRIPT_NAME")
query = Split(Request.ServerVariables("QUERY_STRING"), "&")
    For Each x In query
        a = Split(x, "=")
        If StrComp(a(0), "page_no", vbTextCompare) <> 0 Then
            temp = temp & a(0) & "=" & a(1) & "&"
    End If
		'防止重复page_no
		temp=replace(temp,"&page_no="&int(page_no),"")
    Next
response.write"
" Response.Write("
") response.write"[本页是"&cint(page_no)&"/"&cint(page_total)&"] " if int(page_no)>1 then response.write"[第一页] " response.write"[前一页] " elseif int(page_no)<=1 then response.write"[第一页] [前一页] " end if if int(page_no)后一页] " response.write"[最后一页] " elseif int(page_no)>=int(page_total) then response.write"[后一页] [最后一页] " end if response.write"共"&icount&"条信息 转到" response.write"页" response.write"" response.write"
" end sub %>

有点迷糊了,应该有更好的办法,不过程序确实可以使用了!

本博客所有文章如无特别注明均为原创。
复制或转载请以超链接形式注明转自波斯马,原文地址《管理模块中使用的分页程序(asp)

关键字:

建议订阅本站,及时阅读最新文章!
【上一篇】 【下一篇】

发表评论