主题:这分页代码算是我为论坛做点贡献了。
这是一段真正的通用(好多都是假的就是置顶里面通用也是骗人的)
今天刚好要写通用查询分页 就贴出我这段分页代码来吧。
这也是我在前人基础上改的,没什么技术含量,但好在实用,
就帖出来给大家看看。
不足还请指点。
Function ReplacePage( strPage, intPage) '通用分页
'-------这是通用分页-------------------------------------------------
Dim ScriptAddress, M_ItemUrl, M_item,GetUrl
Dim Query
ScriptAddress = CStr(Request.ServerVariables("SCRIPT_NAME")) Query=Request.ServerVariables("Query_String")
M_ItemUrl = ""
If (Request.QueryString <> "") Then
ScriptAddress = ScriptAddress & "?"
For Each M_item In Request.QueryString
If InStr(Query,M_Item)<>0 Then
M_ItemUrl = M_ItemUrl & M_Item &"="& Server.URLEncode(Request.QueryString(""&M_Item&"")) & "&"
End If
Next
end if
if instr(M_ItemUrl,"&")<>0 then
M_ItemUrl=mid(M_ItemUrl,1,len(M_ItemUrl)-1)
end if
GetUrl = ScriptAddress & M_ItemUrl
'------转换函数------------------------------------------------
Dim ReEx
Set ReEx = New RegExp
ReEx.Global = True
ReEx.Pattern = "((\?|&)" & strPage & "=)\d+"
ReEx.IgnoreCase = False
If ReEx.Test(GetUrl) Then
ReplacePage = ReEx.Replace(GetUrl, "$1" & intPage)
ElseIf InStr(GetUrl, "?") > 0 Then
ReplacePage = GetUrl & "&" & strPage & "=" & intPage
Else
ReplacePage = GetUrl & "?" & strPage & "=" & intPage
End If
End Function
加个调用方法吧。
ReplacePage("page",1)
page是获取页数变量。 1就是当前页
今天刚好要写通用查询分页 就贴出我这段分页代码来吧。
这也是我在前人基础上改的,没什么技术含量,但好在实用,
就帖出来给大家看看。
不足还请指点。
Function ReplacePage( strPage, intPage) '通用分页
'-------这是通用分页-------------------------------------------------
Dim ScriptAddress, M_ItemUrl, M_item,GetUrl
Dim Query
ScriptAddress = CStr(Request.ServerVariables("SCRIPT_NAME")) Query=Request.ServerVariables("Query_String")
M_ItemUrl = ""
If (Request.QueryString <> "") Then
ScriptAddress = ScriptAddress & "?"
For Each M_item In Request.QueryString
If InStr(Query,M_Item)<>0 Then
M_ItemUrl = M_ItemUrl & M_Item &"="& Server.URLEncode(Request.QueryString(""&M_Item&"")) & "&"
End If
Next
end if
if instr(M_ItemUrl,"&")<>0 then
M_ItemUrl=mid(M_ItemUrl,1,len(M_ItemUrl)-1)
end if
GetUrl = ScriptAddress & M_ItemUrl
'------转换函数------------------------------------------------
Dim ReEx
Set ReEx = New RegExp
ReEx.Global = True
ReEx.Pattern = "((\?|&)" & strPage & "=)\d+"
ReEx.IgnoreCase = False
If ReEx.Test(GetUrl) Then
ReplacePage = ReEx.Replace(GetUrl, "$1" & intPage)
ElseIf InStr(GetUrl, "?") > 0 Then
ReplacePage = GetUrl & "&" & strPage & "=" & intPage
Else
ReplacePage = GetUrl & "?" & strPage & "=" & intPage
End If
End Function
加个调用方法吧。
ReplacePage("page",1)
page是获取页数变量。 1就是当前页