服务器之家:专注于服务器技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|JavaScript|易语言|

服务器之家 - 编程语言 - ASP教程 - asp的offset的一个go to page

asp的offset的一个go to page

2019-09-23 10:15asp代码网 ASP教程

呵,指定到第几页,用dw自带的生成的东西,我们可以参考他的思想,代码很多垃圾代码

  1. <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>  
  2. <!--#include file="Connections/conn.asp" -->  
  3. <%  
  4. Dim Recordset1  
  5. Dim Recordset1_cmd  
  6. Dim Recordset1_numRows  
  7.  
  8. Set Recordset1_cmd = Server.CreateObject ("ADODB.Command")  
  9. Recordset1_cmd.ActiveConnection = MM_conn_STRING  
  10. Recordset1_cmd.CommandText = "SELECT * FROM list"  
  11. Recordset1_cmd.Prepared = true  
  12.  
  13. Set Recordset1 = Recordset1_cmd.Execute  
  14. Recordset1_numRows = 0  
  15. %>  
  16. <%  
  17. Dim Repeat1__numRows  
  18. Dim Repeat1__index  
  19.  
  20. Repeat1__numRows = 2  
  21. Repeat1__index = 0  
  22. Recordset1_numRows = Recordset1_numRows + Repeat1__numRows  
  23. %>  
  24.  
  25. <%  
  26. '  *** Recordset Stats, Move To Record, and Go To Record: declare stats variables  
  27.  
  28. Dim Recordset1_total  
  29. Dim Recordset1_first  
  30. Dim Recordset1_last  
  31.  
  32. ' set the record count  
  33. Recordset1_total = Recordset1.RecordCount  
  34.  
  35. ' set the number of rows displayed on this page  
  36. If (Recordset1_numRows < 0) Then  
  37.   Recordset1_numRows = Recordset1_total  
  38. Elseif (Recordset1_numRows = 0) Then  
  39.   Recordset1_numRows = 1  
  40. End If  
  41.  
  42. ' set the first and last displayed record  
  43. Recordset1_first = 1  
  44. Recordset1_last  = Recordset1_first + Recordset1_numRows - 1  
  45.  
  46. if we have the correct record count, check the other stats  
  47. If (Recordset1_total <> -1) Then  
  48.   If (Recordset1_first > Recordset1_total) Then  
  49.     Recordset1_first = Recordset1_total  
  50.   End If  
  51.   If (Recordset1_last > Recordset1_total) Then  
  52.     Recordset1_last = Recordset1_total  
  53.   End If  
  54.   If (Recordset1_numRows > Recordset1_total) Then  
  55.     Recordset1_numRows = Recordset1_total  
  56.   End If  
  57. End If  
  58. %>  
  59.  
  60. <%  
  61. ' *** Recordset Stats: if we don't know the record count, manually count them  
  62.  
  63. If (Recordset1_total = -1) Then  
  64.  
  65.   ' count the total records by iterating through the recordset  
  66.   Recordset1_total=0  
  67.   While (Not Recordset1.EOF)  
  68.     Recordset1_total = Recordset1_total + 1  
  69.     Recordset1.MoveNext  
  70.   Wend  
  71.  
  72.   ' reset the cursor to the beginning  
  73.   If (Recordset1.CursorType > 0) Then  
  74.     Recordset1.MoveFirst  
  75.   Else  
  76.     Recordset1.Requery  
  77.   End If  
  78.  
  79.   ' set the number of rows displayed on this page  
  80.   If (Recordset1_numRows < 0 Or Recordset1_numRows > Recordset1_total) Then  
  81.     Recordset1_numRows = Recordset1_total  
  82.   End If  
  83.  
  84.   ' set the first and last displayed record  
  85.   Recordset1_first = 1  
  86.   Recordset1_last = Recordset1_first + Recordset1_numRows - 1  
  87.  
  88.   If (Recordset1_first > Recordset1_total) Then  
  89.     Recordset1_first = Recordset1_total  
  90.   End If  
  91.   If (Recordset1_last > Recordset1_total) Then  
  92.     Recordset1_last = Recordset1_total  
  93.   End If  
  94.  
  95. End If  
  96. %>  
  97. <%  
  98. Dim MM_paramName  
  99. %>  
  100. <%  
  101. ' *** Move To Record and Go To Record: declare variables  
  102.  
  103. Dim MM_rs  
  104. Dim MM_rsCount  
  105. Dim MM_size  
  106. Dim MM_uniqueCol  
  107. Dim MM_offset  
  108. Dim MM_atTotal  
  109. Dim MM_paramIsDefined  
  110.  
  111. Dim MM_param  
  112. Dim MM_index  
  113.  
  114. Set MM_rs    = Recordset1  
  115. MM_rsCount   = Recordset1_total  
  116. MM_size      = Recordset1_numRows  
  117. MM_uniqueCol = "id"  
  118. MM_paramName = "page"  
  119. MM_offset = 0  
  120. MM_atTotal = false  
  121. MM_paramIsDefined = false  
  122. If (MM_paramName <> "") Then  
  123.   MM_paramIsDefined = (Request.QueryString(MM_paramName) <> "")  
  124. End If  
  125. %>  
  126. <%  
  127. ' *** Move To Record: handle 'index' or 'offset' parameter  
  128.  
  129. if (Not MM_paramIsDefined And MM_rsCount <> 0) then  
  130.  
  131.   ' use index parameter if defined, otherwise use offset parameter  
  132.   MM_param = Request.QueryString("index")  
  133.   If (MM_param = "") Then  
  134.     MM_param = Request.QueryString("offset")  
  135.   End If  
  136.   If (MM_param <> "") Then  
  137.     MM_offset = Int(MM_param)  
  138.   End If  
  139.  
  140.   ' if we have a record count, check if we are past the end of the recordset  
  141.   If (MM_rsCount <> -1) Then  
  142.     If (MM_offset >= MM_rsCount Or MM_offset = -1) Then  ' past end or move last  
  143.       If ((MM_rsCount Mod MM_size) > 0) Then         ' last page not a full repeat region  
  144.         MM_offset = MM_rsCount - (MM_rsCount Mod MM_size)  
  145.       Else  
  146.         MM_offset = MM_rsCount - MM_size  
  147.       End If  
  148.     End If  
  149.   End If  
  150.  
  151.   ' move the cursor to the selected record  
  152.   MM_index = 0  
  153.   While ((Not MM_rs.EOF) And (MM_index < MM_offset Or MM_offset = -1))  
  154.     MM_rs.MoveNext  
  155.     MM_index = MM_index + 1  
  156.   Wend  
  157.   If (MM_rs.EOF) Then  
  158.     MM_offset = MM_index  ' set MM_offset to the last possible record  
  159.   End If  
  160.  
  161. End If  
  162. %>  
  163. <%  
  164. ' *** Move To Specific Record: handle detail parameter  
  165.  
  166. If (MM_paramIsDefined And MM_rsCount <> 0) Then  
  167.  
  168.   ' get the value of the parameter  
  169.   MM_param = Request.QueryString(MM_paramName)  
  170.  
  171.   ' find the record with the unique column value equal to the parameter value  
  172.   MM_offset = 0  
  173.   Do While (Not MM_rs.EOF)  
  174.     If (CStr(MM_rs.Fields.Item(MM_uniqueCol).Value) = MM_param) Then  
  175.       Exit Do  
  176.     End If  
  177.     MM_offset = MM_offset + 1  
  178.     MM_rs.MoveNext  
  179.   Loop  
  180.  
  181.   ' if not found, set the number of records and reset the cursor  
  182.   If (MM_rs.EOF) Then  
  183.     If (MM_rsCount < 0) Then  
  184.       MM_rsCount = MM_offset  
  185.     End If  
  186.     If (MM_size < 0 Or MM_size > MM_offset) Then  
  187.       MM_size = MM_offset  
  188.     End If  
  189.     MM_offset = 0  
  190.  
  191.     ' reset the cursor to the beginning  
  192.     If (MM_rs.CursorType > 0) Then  
  193.       MM_rs.MoveFirst  
  194.     Else  
  195.       MM_rs.Close  
  196.       MM_rs.Open  
  197.     End If  
  198.   End If  
  199.  
  200. End If  
  201. %>  
  202. <%  
  203. ' *** Move To Record: if we dont know the record count, check the display range  
  204.  
  205. If (MM_rsCount = -1) Then  
  206.  
  207.   ' walk to the end of the display range for this page  
  208.   MM_index = MM_offset  
  209.   While (Not MM_rs.EOF And (MM_size < 0 Or MM_index < MM_offset + MM_size))  
  210.     MM_rs.MoveNext  
  211.     MM_index = MM_index + 1  
  212.   Wend  
  213.  
  214.   ' if we walked off the end of the recordset, set MM_rsCount and MM_size  
  215.   If (MM_rs.EOF) Then  
  216.     MM_rsCount = MM_index  
  217.     If (MM_size < 0 Or MM_size > MM_rsCount) Then  
  218.       MM_size = MM_rsCount  
  219.     End If  
  220.   End If  
  221.  
  222.   ' if we walked off the end, set the offset based on page size  
  223.   If (MM_rs.EOF And Not MM_paramIsDefined) Then  
  224.     If (MM_offset > MM_rsCount - MM_size Or MM_offset = -1) Then  
  225.       If ((MM_rsCount Mod MM_size) > 0) Then  
  226.         MM_offset = MM_rsCount - (MM_rsCount Mod MM_size)  
  227.       Else  
  228.         MM_offset = MM_rsCount - MM_size  
  229.       End If  
  230.     End If  
  231.   End If  
  232.  
  233.   ' reset the cursor to the beginning  
  234.   If (MM_rs.CursorType > 0) Then  
  235.     MM_rs.MoveFirst  
  236.   Else  
  237.     MM_rs.Requery  
  238.   End If  
  239.  
  240.   ' move the cursor to the selected record  
  241.   MM_index = 0  
  242.   While (Not MM_rs.EOF And MM_index < MM_offset)  
  243.     MM_rs.MoveNext  
  244.     MM_index = MM_index + 1  
  245.   Wend  
  246. End If  
  247. %>  
  248. <%  
  249. ' *** Move To Record: update recordset stats  
  250.  
  251. ' set the first and last displayed record  
  252. Recordset1_first = MM_offset + 1  
  253. Recordset1_last  = MM_offset + MM_size  
  254.  
  255. If (MM_rsCount <> -1) Then  
  256.   If (Recordset1_first > MM_rsCount) Then  
  257.     Recordset1_first = MM_rsCount  
  258.   End If  
  259.   If (Recordset1_last > MM_rsCount) Then  
  260.     Recordset1_last = MM_rsCount  
  261.   End If  
  262. End If  
  263.  
  264. ' set the boolean used by hide region to check if we are on the last record  
  265. MM_atTotal = (MM_rsCount <> -1 And MM_offset + MM_size >= MM_rsCount)  
  266. %>  
  267.  
  268. <%  
  269. ' *** Go To Record and Move To Record: create strings for maintaining URL and Form parameters  
  270.  
  271. Dim MM_keepNone  
  272. Dim MM_keepURL  
  273. Dim MM_keepForm  
  274. Dim MM_keepBoth  
  275.  
  276. Dim MM_removeList  
  277. Dim MM_item  
  278. Dim MM_nextItem  
  279.  
  280. ' create the list of parameters which should not be maintained  
  281. MM_removeList = "&index="  
  282. If (MM_paramName <> "") Then  
  283.   MM_removeList = MM_removeList & "&" & MM_paramName & "="  
  284. End If  
  285.  
  286. MM_keepURL=""  
  287. MM_keepForm=""  
  288. MM_keepBoth=""  
  289. MM_keepNone=""  
  290.  
  291. ' add the URL parameters to the MM_keepURL string  
  292. For Each MM_item In Request.QueryString  
  293.   MM_nextItem = "&" & MM_item & "="  
  294.   If (InStr(1,MM_removeList,MM_nextItem,1) = 0) Then  
  295.     MM_keepURL = MM_keepURL & MM_nextItem & Server.URLencode(Request.QueryString(MM_item))  
  296.   End If  
  297. Next  
  298.  
  299. ' add the Form variables to the MM_keepForm string  
  300. For Each MM_item In Request.Form  
  301.   MM_nextItem = "&" & MM_item & "="  
  302.   If (InStr(1,MM_removeList,MM_nextItem,1) = 0) Then  
  303.     MM_keepForm = MM_keepForm & MM_nextItem & Server.URLencode(Request.Form(MM_item))  
  304.   End If  
  305. Next  
  306.  
  307. ' create the Form + URL string and remove the intial '&' from each of the strings  
  308. MM_keepBoth = MM_keepURL & MM_keepForm  
  309. If (MM_keepBoth <> "") Then  
  310.   MM_keepBoth = Right(MM_keepBoth, Len(MM_keepBoth) - 1)  
  311. End If  
  312. If (MM_keepURL <> "")  Then  
  313.   MM_keepURL  = Right(MM_keepURL, Len(MM_keepURL) - 1)  
  314. End If  
  315. If (MM_keepForm <> "") Then  
  316.   MM_keepForm = Right(MM_keepForm, Len(MM_keepForm) - 1)  
  317. End If  
  318.  
  319. ' a utility function used for adding additional parameters to these strings  
  320. Function MM_joinChar(firstItem)  
  321.   If (firstItem <> "") Then  
  322.     MM_joinChar = "&"  
  323.   Else  
  324.     MM_joinChar = ""  
  325.   End If  
  326. End Function  
  327. %>  
  328. <%  
  329. ' *** Move To Record: set the strings for the first, last, next, and previous links  
  330.  
  331. Dim MM_keepMove  
  332. Dim MM_moveParam  
  333. Dim MM_moveFirst  
  334. Dim MM_moveLast  
  335. Dim MM_moveNext  
  336. Dim MM_movePrev  
  337.  
  338. Dim MM_urlStr  
  339. Dim MM_paramList  
  340. Dim MM_paramIndex  
  341. Dim MM_nextParam  
  342.  
  343. MM_keepMove = MM_keepBoth  
  344. MM_moveParam = "index"  
  345.  
  346. ' if the page has a repeated region, remove 'offset' from the maintained parameters  
  347. If (MM_size > 1) Then  
  348.   MM_moveParam = "offset"  
  349.   If (MM_keepMove <> "") Then  
  350.     MM_paramList = Split(MM_keepMove, "&")  
  351.     MM_keepMove = ""  
  352.     For MM_paramIndex = 0 To UBound(MM_paramList)  
  353.       MM_nextParam = Left(MM_paramList(MM_paramIndex), InStr(MM_paramList(MM_paramIndex),"=") - 1)  
  354.       If (StrComp(MM_nextParam,MM_moveParam,1) <> 0) Then  
  355.         MM_keepMove = MM_keepMove & "&" & MM_paramList(MM_paramIndex)  
  356.       End If  
  357.     Next  
  358.     If (MM_keepMove <> "") Then  
  359.       MM_keepMove = Right(MM_keepMove, Len(MM_keepMove) - 1)  
  360.     End If  
  361.   End If  
  362. End If  
  363.  
  364. ' set the strings for the move to links  
  365. If (MM_keepMove <> "") Then  
  366.   MM_keepMove = Server.HTMLEncode(MM_keepMove) & "&"  
  367. End If  
  368.  
  369. MM_urlStr = Request.ServerVariables("URL") & "?" & MM_keepMove & MM_moveParam & "="  
  370.  
  371. MM_moveFirst = MM_urlStr & "0"  
  372. MM_moveLast  = MM_urlStr & "-1"  
  373. MM_moveNext  = MM_urlStr & CStr(MM_offset + MM_size)  
  374. If (MM_offset - MM_size < 0) Then  
  375.   MM_movePrev = MM_urlStr & "0"  
  376. Else  
  377.   MM_movePrev = MM_urlStr & CStr(MM_offset - MM_size)  
  378. End If  
  379. %>  
  380. <%  
  381. if request.QueryString("page")<>"" then  
  382.   Recordset1_last=request.QueryString("page")*MM_size  
  383.   offset=Recordset1_last-MM_size  
  384.   url="?offset="&offset  
  385.   response.Redirect(url)  
  386. end if  
  387. %>  
  388. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  389. <html xmlns="http://www.w3.org/1999/xhtml">  
  390. <head>  
  391. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
  392. <title>Untitled Document</title>  
  393. </head>  
  394.  
  395. <body>  
  396. <%  
  397. While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF))  
  398. %>  
  399.   <div><%=(Recordset1.Fields.Item("id").Value)%></div>  
  400.   <%  
  401.   Repeat1__index=Repeat1__index+1  
  402.   Repeat1__numRows=Repeat1__numRows-1  
  403.   Recordset1.MoveNext()  
  404. Wend  
  405. %>  
  406. <div> 总数<%=(Recordset1_total)%> 共<%=Recordset1_total/MM_size%>页当前第<%=(Recordset1_last/MM_size)%>页 <a href="<%=MM_moveFirst%>">首页</a> <a href="<%=MM_movePrev%>">上一页</a> <a href="<%=MM_moveNext%>">下一页</a> <a href="<%=MM_moveLast%>">最后一页</a>  
  407.   <label>  
  408.   <input name="page" type="text" id="page" value="<%=(Recordset1_last/MM_size)%>" size="5" />  
  409.   <input name="button" type="submit" id="button" onclick="window.location.href='?page='+page.value" value="go" />  
  410.   </label>  
  411.   fist<%=(Recordset1_first)%> last<%=(Recordset1_last)%></div>  
  412. </body>  
  413. </html>  
  414. <%  
  415. Recordset1.Close()  
  416. Set Recordset1 = Nothing  
  417. %>  

延伸 · 阅读

精彩推荐