主题:[讨论]vb实现ASP组件
A.asp
<%
Sub PageTop(Page_Mode)
totalPut=Rs.Recordcount
IF currentPage<1 then
currentPage=1
End IF
IF (currentPage-1)*MaxPerPage>totalput then
IF (totalPut mod MaxPerPage)=0 then
currentPage=totalPut \ MaxPerPage
Else
currentPage=totalPut \ MaxPerPage + 1
End IF
End IF
IF currentPage=1 then
showContent
showPage totalput,MaxPerPage,Page_Mode,"ID="&amp;Request("ID")
Else
IF (currentPage-1)*MaxPerPage<totalPut then
Rs.Move (currentPage-1)*MaxPerPage
dim Vookmark
Bookmark=Rs.Bookmark
showContent
showPage totalput,MaxPerPage,Page_Mode,"ID="&amp;Request("ID")
Else
currentPage=1
showContent
showPage totalput,MaxPerPage,Page_Mode,"ID="&amp;Request("ID")
End IF
End IF
End Sub
Function ShowPage(totalnumber,maxperPage,Page_Mode,filename)
Dim n
Select Case Page_Mode
Case "1"
IF totalnumber mod maxperPage=0 then
n=totalnumber \ maxperPage
Else
n=totalnumber \ maxperPage + 1
End IF
Response.Write "<span style='font-weight: bold; color: #333333'>共</span><font style='color: #FF0000;font-weight: bold;'>"&amp;n&amp;"</font><span style='font-weight: bold; color: #333333'>页&amp;nbsp;第</span><font style='color: #FF0000;font-weight: bold;'>"&amp;currentPage&amp;"</font><span style='font-weight: bold; color: #333333'>页</span>&amp;nbsp;"
IF CurrentPage<2 then
Response.Write "<img src='Images/Page/First_Page.gif' width='16' height='15' border='0' align='absmiddle'>&amp;nbsp;<img src='Images/Page/Previous_Page.gif' width='46' height='15' align='absmiddle'>&amp;nbsp;"
else
Response.Write "<img src='Images/Page/First_Page_Act.gif' onClick=""javascript:window.open('?Page=1&amp;"&amp;filename&amp;"&amp;Reult='+Search.Reult.value,'_self','')"" border='0' align='absmiddle'>&amp;nbsp;"
Response.Write "<img src='Images/Page/Previous_Page_Act.gif' onClick=""javascript:window.open('?Page="&amp;CurrentPage-1&amp;"&amp;"&amp;filename&amp;"&amp;Reult='+Search.Reult.value,'_self','')"" border='0' align='absmiddle'>&amp;nbsp;"
End IF
IF n-currentPage<1 then
Response.Write "&amp;nbsp;<img src='Images/Page/Next_Page.gif' width='46' height='15' align='absmiddle'>&amp;nbsp;<img src='Images/Page/Last_Page.gif' width='16' height='15' border='0' align='absmiddle'>"
Else
Response.Write "<img src='Images/Page/Next_Page_Act.gif' onClick=""javascript:window.open('?Page="&amp;CurrentPage+1&amp;"&amp;"&amp;filename&amp;"&amp;Reult='+Search.Reult.value,'_self','')"" border='0' align='absmiddle'>&amp;nbsp;"
Response.Write "<img src='Images/Page/Last_Page_Act.gif' onClick=""javascript:window.open('?Page="&amp;n&amp;"&amp;"&amp;filename&amp;"&amp;Reult='+Search.Reult.value,'_self','')"" border='0' align='absmiddle'>"
End IF
IF Request("ID")<>"" Then Response.Write "&amp;nbsp;&amp;nbsp;<input type='hidden' name='ID' value='"&amp;Request("ID")&amp;"'>"
IF Request("ID")<>"" Then Response.Write "&amp;nbsp;&amp;nbsp;<input type='hidden' name='BID' value='"&amp;Request("BID")&amp;"'>"
Response.Write "&amp;nbsp;<select name=Page size=1 onChange=""javascript:window.open('?Page='+this.value+'&amp;"&amp;filename&amp;"&amp;Reult='+Search.Reult.value,'_self','')"">"
For NX=1 to n
IF Cstr(NX)=Cstr(CurrentPage) then
Response.Write "<option value='"&amp;CurrentPage&amp;"' selected>第"&amp;NX&amp;"页</option>"
Else
Response.Write "<option value='"&amp;NX&amp;"'>第"&amp;NX&amp;"页</option>"
End IF
Next
Response.Write "</select>"
End Select
End Function
%>
建立Db.mdb 有一个ID字段既可测试
B.Asp
<!-- #Include File = "A.Asp" -->
<%
Connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&amp;Server.MapPath("Db.mdb")
Set conn=Server.CreateObject("ADODB.Connection")
conn.open ConnStr
Action=Request("Action")
Select Case Action
Case "
MaxPerPage=10
dim totalPut
dim CurrentPage
dim TotalPages
dim a,j
IF not isempty(Read_Page) then
currentPage=Read_Page
Else
currentPage=1
End IF
Set Rs = Server.CreateObject("ADODB.Recordset")
Rs.Open "Select * From [A] Order By ID",Conn,1,1
PageTop(1)
Sub ShowContent
Call List
End Sub
Response.Write vbcrlf&amp;" </td>" &amp;_
vbcrlf&amp;" </tr>" &amp;_
vbcrlf&amp;" </Form>" &amp;_
vbcrlf&amp;"</table>"
End Select
Sub List
%>
<table width="153" border="0" cellpadding="5" cellspacing="1" bgcolor="#D4D0C8">
<Form Method=Post name=pic Action="?Action=Add">
<tr bgcolor="#EFEFEF">
<td height="210" valign="top">
<%
IF Not Rs.EOF Then
Do While Not Rs.EOF
Response.Write Rs("ID")&amp;"
"
Rs.MoveNext
a=a+1
IF a>=MaxPerPage Then Exit DO
Loop
End IF
%>
<tr bgcolor="#EFEFEF" height=30>
<td>
<%
End Sub
%>
在vb中建立DLL,工程名Easy,类名page
Option Explicit
Dim Rp As Response
Dim Rq As Request
Dim Ap As Application
Dim Sr As Server
Dim Sn As Session
Dim n As Long
Dim NX As Long
Dim ID As Long
Dim Totalput As Long
Dim CurrentPage As Long
Dim Bookmark As Long
Dim Totalnumber As Long
Dim PageMode As String
Dim Filename As String
Dim StrConn As String
Dim ShowPageSize As Variant
Dim Conn As New ADODB.Connection
Dim Rs As New ADODB.Recordset
Public Sub OnStartPage(myScriptingContent As ScriptingContext)
Set Rp = myScriptingContent.Rp
Set Rq = myScriptingContent.Rq
Set Sr = myScriptingContent.Server
Set Ap = myScriptingContent.Application
Set Sn = myScriptingContent.Session
End Sub
Public Sub OnEndPage()
Set Rp = Nothing
Set Rq = Nothing
Set Sr = Nothing
Set Ap = Nothing
Set Sn = Nothing
End Sub
Public Sub PageTop(PageMode)
Totalput = Rs.RecordCount
If CurrentPage < 1 Then
CurrentPage = 1
End If
If (CurrentPage - 1) * MaxperPage > Totalput Then
If (Totalput Mod MaxperPage) = 0 Then
CurrentPage = Totalput \ MaxperPage
Else
CurrentPage = Totalput \ MaxperPage + 1
End If
End If
If CurrentPage = 1 Then
Rp.Write ShowContent
ShowPage Totalput, MaxperPage, PageMode, "ID=" & Rq("ID")
Else
If (CurrentPage - 1) * MaxperPage < Totalput Then
Rs.Move (CurrentPage - 1) * MaxperPage
Bookmark = Rs.Bookmark
Rp.Write ShowContent
ShowPage Totalput, MaxperPage, PageMode, "ID=" & Rq("ID")
Else
CurrentPage = 1
Rp.Write ShowContent
ShowPage Totalput, MaxperPage, PageMode, "ID=" & Rq("ID")
End If
End If
End Sub
Public Function ShowPage(Totalnumber, MaxperPage, PageMode, Filename) As Variant
Select Case PageMode
Case "1"
If Totalnumber Mod MaxperPage = 0 Then
n = Totalnumber \ MaxperPage
Else
n = Totalnumber \ MaxperPage + 1
End If
Rp.Write "<span style='font-weight: bold; color: #333333'>共</span><font style='color: #FF0000;font-weight: bold;'>" + n + "</font><span style='font-weight: bold; color: #333333'>页 第</span><font style='color: #FF0000;font-weight: bold;'>" + CurrentPage + "</font><span style='font-weight: bold; color: #333333'>页</span> "
If CurrentPage < 2 Then
Rp.Write "<img src='Images/Page/First_Page.gif' width='16' height='15' border='0' align='absmiddle'> <img src='Images/Page/Previous_Page.gif' width='46' height='15' align='absmiddle'> "
Else
Rp.Write "<img src='Images/Page/First_Page_Act.gif' onClick=""javascript:window.open('?Page=1&" + Filename + "&Reult='+Search.Reult.value,'_self','')"" border='0' align='absmiddle'> "
Rp.Write "<img src='Images/Page/Previous_Page_Act.gif' onClick=""javascript:window.open('?Page=" + CurrentPage - 1 + "&" + Filename + "&Reult='+Search.Reult.value,'_self','')"" border='0' align='absmiddle'> "
End If
If n - CurrentPage < 1 Then
Rp.Write " <img src='Images/Page/Next_Page.gif' width='46' height='15' align='absmiddle'> <img src='Images/Page/Last_Page.gif' width='16' height='15' border='0' align='absmiddle'>"
Else
Rp.Write "<img src='Images/Page/Next_Page_Act.gif' onClick=""javascript:window.open('?Page=" + CurrentPage + 1 + "&" + Filename + "&Reult='+Search.Reult.value,'_self','')"" border='0' align='absmiddle'> "
Rp.Write "<img src='Images/Page/Last_Page_Act.gif' onClick=""javascript:window.open('?Page=" + n + "&" + Filename + "&Reult='+Search.Reult.value,'_self','')"" border='0' align='absmiddle'>"
End If
If Rq("ID") <> "" Then Rp.Write " <input type='hidden' name='ID' value='" & Rq("ID") & "'>"
If Rq("ID") <> "" Then Rp.Write " <input type='hidden' name='BID' value='" & Rq("BID") & "'>"
Rp.Write " <select name=Page size=1 onChange=""javascript:window.open('?Page='+this.value+'&" + Filename + "&Reult='+Search.Reult.value,'_self','')"">"
For NX = 1 To n
If CStr(NX) = CStr(CurrentPage) Then
Rp.Write "<option value='" + CurrentPage + "' selected>第" + NX + "页</option>"
Else
Rp.Write "<option value='" + NX + "'>第" + NX + "页</option>"
End If
Next
Rp.Write "</select>"
End Select
End Function
Public Property Get MaxperPage() As Variant
MaxperPage = ShowPageSize
End Property
Public Property Let MaxperPage(ByVal vNewValue As Variant)
ShowPageSize = vNewValue
End Property
Public Property Get ShowContent() As Variant
End Property
把以下替换在B.asp的PageTop(1)处
Set Page=Server.CreateObject("Easy.Page")
Page.PageTop(1)
怎么也得不到原来ASP中的分页样子!
高分求助!
<%
Sub PageTop(Page_Mode)
totalPut=Rs.Recordcount
IF currentPage<1 then
currentPage=1
End IF
IF (currentPage-1)*MaxPerPage>totalput then
IF (totalPut mod MaxPerPage)=0 then
currentPage=totalPut \ MaxPerPage
Else
currentPage=totalPut \ MaxPerPage + 1
End IF
End IF
IF currentPage=1 then
showContent
showPage totalput,MaxPerPage,Page_Mode,"ID="&amp;Request("ID")
Else
IF (currentPage-1)*MaxPerPage<totalPut then
Rs.Move (currentPage-1)*MaxPerPage
dim Vookmark
Bookmark=Rs.Bookmark
showContent
showPage totalput,MaxPerPage,Page_Mode,"ID="&amp;Request("ID")
Else
currentPage=1
showContent
showPage totalput,MaxPerPage,Page_Mode,"ID="&amp;Request("ID")
End IF
End IF
End Sub
Function ShowPage(totalnumber,maxperPage,Page_Mode,filename)
Dim n
Select Case Page_Mode
Case "1"
IF totalnumber mod maxperPage=0 then
n=totalnumber \ maxperPage
Else
n=totalnumber \ maxperPage + 1
End IF
Response.Write "<span style='font-weight: bold; color: #333333'>共</span><font style='color: #FF0000;font-weight: bold;'>"&amp;n&amp;"</font><span style='font-weight: bold; color: #333333'>页&amp;nbsp;第</span><font style='color: #FF0000;font-weight: bold;'>"&amp;currentPage&amp;"</font><span style='font-weight: bold; color: #333333'>页</span>&amp;nbsp;"
IF CurrentPage<2 then
Response.Write "<img src='Images/Page/First_Page.gif' width='16' height='15' border='0' align='absmiddle'>&amp;nbsp;<img src='Images/Page/Previous_Page.gif' width='46' height='15' align='absmiddle'>&amp;nbsp;"
else
Response.Write "<img src='Images/Page/First_Page_Act.gif' onClick=""javascript:window.open('?Page=1&amp;"&amp;filename&amp;"&amp;Reult='+Search.Reult.value,'_self','')"" border='0' align='absmiddle'>&amp;nbsp;"
Response.Write "<img src='Images/Page/Previous_Page_Act.gif' onClick=""javascript:window.open('?Page="&amp;CurrentPage-1&amp;"&amp;"&amp;filename&amp;"&amp;Reult='+Search.Reult.value,'_self','')"" border='0' align='absmiddle'>&amp;nbsp;"
End IF
IF n-currentPage<1 then
Response.Write "&amp;nbsp;<img src='Images/Page/Next_Page.gif' width='46' height='15' align='absmiddle'>&amp;nbsp;<img src='Images/Page/Last_Page.gif' width='16' height='15' border='0' align='absmiddle'>"
Else
Response.Write "<img src='Images/Page/Next_Page_Act.gif' onClick=""javascript:window.open('?Page="&amp;CurrentPage+1&amp;"&amp;"&amp;filename&amp;"&amp;Reult='+Search.Reult.value,'_self','')"" border='0' align='absmiddle'>&amp;nbsp;"
Response.Write "<img src='Images/Page/Last_Page_Act.gif' onClick=""javascript:window.open('?Page="&amp;n&amp;"&amp;"&amp;filename&amp;"&amp;Reult='+Search.Reult.value,'_self','')"" border='0' align='absmiddle'>"
End IF
IF Request("ID")<>"" Then Response.Write "&amp;nbsp;&amp;nbsp;<input type='hidden' name='ID' value='"&amp;Request("ID")&amp;"'>"
IF Request("ID")<>"" Then Response.Write "&amp;nbsp;&amp;nbsp;<input type='hidden' name='BID' value='"&amp;Request("BID")&amp;"'>"
Response.Write "&amp;nbsp;<select name=Page size=1 onChange=""javascript:window.open('?Page='+this.value+'&amp;"&amp;filename&amp;"&amp;Reult='+Search.Reult.value,'_self','')"">"
For NX=1 to n
IF Cstr(NX)=Cstr(CurrentPage) then
Response.Write "<option value='"&amp;CurrentPage&amp;"' selected>第"&amp;NX&amp;"页</option>"
Else
Response.Write "<option value='"&amp;NX&amp;"'>第"&amp;NX&amp;"页</option>"
End IF
Next
Response.Write "</select>"
End Select
End Function
%>
建立Db.mdb 有一个ID字段既可测试
B.Asp
<!-- #Include File = "A.Asp" -->
<%
Connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&amp;Server.MapPath("Db.mdb")
Set conn=Server.CreateObject("ADODB.Connection")
conn.open ConnStr
Action=Request("Action")
Select Case Action
Case "
MaxPerPage=10
dim totalPut
dim CurrentPage
dim TotalPages
dim a,j
IF not isempty(Read_Page) then
currentPage=Read_Page
Else
currentPage=1
End IF
Set Rs = Server.CreateObject("ADODB.Recordset")
Rs.Open "Select * From [A] Order By ID",Conn,1,1
PageTop(1)
Sub ShowContent
Call List
End Sub
Response.Write vbcrlf&amp;" </td>" &amp;_
vbcrlf&amp;" </tr>" &amp;_
vbcrlf&amp;" </Form>" &amp;_
vbcrlf&amp;"</table>"
End Select
Sub List
%>
<table width="153" border="0" cellpadding="5" cellspacing="1" bgcolor="#D4D0C8">
<Form Method=Post name=pic Action="?Action=Add">
<tr bgcolor="#EFEFEF">
<td height="210" valign="top">
<%
IF Not Rs.EOF Then
Do While Not Rs.EOF
Response.Write Rs("ID")&amp;"
"
Rs.MoveNext
a=a+1
IF a>=MaxPerPage Then Exit DO
Loop
End IF
%>
<tr bgcolor="#EFEFEF" height=30>
<td>
<%
End Sub
%>
在vb中建立DLL,工程名Easy,类名page
Option Explicit
Dim Rp As Response
Dim Rq As Request
Dim Ap As Application
Dim Sr As Server
Dim Sn As Session
Dim n As Long
Dim NX As Long
Dim ID As Long
Dim Totalput As Long
Dim CurrentPage As Long
Dim Bookmark As Long
Dim Totalnumber As Long
Dim PageMode As String
Dim Filename As String
Dim StrConn As String
Dim ShowPageSize As Variant
Dim Conn As New ADODB.Connection
Dim Rs As New ADODB.Recordset
Public Sub OnStartPage(myScriptingContent As ScriptingContext)
Set Rp = myScriptingContent.Rp
Set Rq = myScriptingContent.Rq
Set Sr = myScriptingContent.Server
Set Ap = myScriptingContent.Application
Set Sn = myScriptingContent.Session
End Sub
Public Sub OnEndPage()
Set Rp = Nothing
Set Rq = Nothing
Set Sr = Nothing
Set Ap = Nothing
Set Sn = Nothing
End Sub
Public Sub PageTop(PageMode)
Totalput = Rs.RecordCount
If CurrentPage < 1 Then
CurrentPage = 1
End If
If (CurrentPage - 1) * MaxperPage > Totalput Then
If (Totalput Mod MaxperPage) = 0 Then
CurrentPage = Totalput \ MaxperPage
Else
CurrentPage = Totalput \ MaxperPage + 1
End If
End If
If CurrentPage = 1 Then
Rp.Write ShowContent
ShowPage Totalput, MaxperPage, PageMode, "ID=" & Rq("ID")
Else
If (CurrentPage - 1) * MaxperPage < Totalput Then
Rs.Move (CurrentPage - 1) * MaxperPage
Bookmark = Rs.Bookmark
Rp.Write ShowContent
ShowPage Totalput, MaxperPage, PageMode, "ID=" & Rq("ID")
Else
CurrentPage = 1
Rp.Write ShowContent
ShowPage Totalput, MaxperPage, PageMode, "ID=" & Rq("ID")
End If
End If
End Sub
Public Function ShowPage(Totalnumber, MaxperPage, PageMode, Filename) As Variant
Select Case PageMode
Case "1"
If Totalnumber Mod MaxperPage = 0 Then
n = Totalnumber \ MaxperPage
Else
n = Totalnumber \ MaxperPage + 1
End If
Rp.Write "<span style='font-weight: bold; color: #333333'>共</span><font style='color: #FF0000;font-weight: bold;'>" + n + "</font><span style='font-weight: bold; color: #333333'>页 第</span><font style='color: #FF0000;font-weight: bold;'>" + CurrentPage + "</font><span style='font-weight: bold; color: #333333'>页</span> "
If CurrentPage < 2 Then
Rp.Write "<img src='Images/Page/First_Page.gif' width='16' height='15' border='0' align='absmiddle'> <img src='Images/Page/Previous_Page.gif' width='46' height='15' align='absmiddle'> "
Else
Rp.Write "<img src='Images/Page/First_Page_Act.gif' onClick=""javascript:window.open('?Page=1&" + Filename + "&Reult='+Search.Reult.value,'_self','')"" border='0' align='absmiddle'> "
Rp.Write "<img src='Images/Page/Previous_Page_Act.gif' onClick=""javascript:window.open('?Page=" + CurrentPage - 1 + "&" + Filename + "&Reult='+Search.Reult.value,'_self','')"" border='0' align='absmiddle'> "
End If
If n - CurrentPage < 1 Then
Rp.Write " <img src='Images/Page/Next_Page.gif' width='46' height='15' align='absmiddle'> <img src='Images/Page/Last_Page.gif' width='16' height='15' border='0' align='absmiddle'>"
Else
Rp.Write "<img src='Images/Page/Next_Page_Act.gif' onClick=""javascript:window.open('?Page=" + CurrentPage + 1 + "&" + Filename + "&Reult='+Search.Reult.value,'_self','')"" border='0' align='absmiddle'> "
Rp.Write "<img src='Images/Page/Last_Page_Act.gif' onClick=""javascript:window.open('?Page=" + n + "&" + Filename + "&Reult='+Search.Reult.value,'_self','')"" border='0' align='absmiddle'>"
End If
If Rq("ID") <> "" Then Rp.Write " <input type='hidden' name='ID' value='" & Rq("ID") & "'>"
If Rq("ID") <> "" Then Rp.Write " <input type='hidden' name='BID' value='" & Rq("BID") & "'>"
Rp.Write " <select name=Page size=1 onChange=""javascript:window.open('?Page='+this.value+'&" + Filename + "&Reult='+Search.Reult.value,'_self','')"">"
For NX = 1 To n
If CStr(NX) = CStr(CurrentPage) Then
Rp.Write "<option value='" + CurrentPage + "' selected>第" + NX + "页</option>"
Else
Rp.Write "<option value='" + NX + "'>第" + NX + "页</option>"
End If
Next
Rp.Write "</select>"
End Select
End Function
Public Property Get MaxperPage() As Variant
MaxperPage = ShowPageSize
End Property
Public Property Let MaxperPage(ByVal vNewValue As Variant)
ShowPageSize = vNewValue
End Property
Public Property Get ShowContent() As Variant
End Property
把以下替换在B.asp的PageTop(1)处
Set Page=Server.CreateObject("Easy.Page")
Page.PageTop(1)
怎么也得不到原来ASP中的分页样子!
高分求助!