473,406 Members | 2,387 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

asp pagination help

hi im using below code for pagination. i want 1 help,when i click the name(link)it should go to editpage.asp.my question is how can i add links to names?
Expand|Select|Wrap|Line Numbers
  1. <%
  2. Option Explicit
  3. Const adOpenStatic   = 3
  4. Const adLockReadOnly = 1
  5. Const adCmdText      = &H0001
  6. Dim CONN_STRING
  7. CONN_STRING = "Driver={SQL Server};Server=.;Database=my_tables;uid=sa;pwd=travelzone"
  8. Dim iPageSize 'How big our pages are
  9. Dim iPageCount 'The number of pages we get back
  10. Dim iPageCurrent 'The page we want to show
  11. Dim strOrderBy 'A fake parameter used to illustrate passing them
  12. Dim sql 'SQL command to execute
  13. Dim conn 'The ADODB connection object
  14. Dim rs 'The ADODB recordset object
  15. Dim iRecordsShown  'Loop controller for displaying just iPageSize records
  16. Dim iFieldCount
  17. Dim iRecordCount
  18. Dim LoopRecordCount
  19. Dim pageNum
  20. Dim counter
  21. Dim markShowPage
  22. Dim I, J 'Standard looping var
  23. iPageSize = 10
  24. ' Retrieve page to show or default to 1
  25. If Request.QueryString("page") = "" Then
  26.     iPageCurrent = 1
  27. Else
  28.     iPageCurrent = CInt(Request.QueryString("page"))
  29. End If
  30.  
  31. sql = "SELECT * from employee order by empid asc;"
  32.  
  33. Set conn = Server.CreateObject("ADODB.Connection")
  34. conn.Open CONN_STRING
  35. ' Create recordset and set the page size
  36. Set rs = Server.CreateObject("ADODB.Recordset")
  37. rs.PageSize = iPageSize
  38. rs.CacheSize = iPageSize
  39. ' Open RS
  40. rs.Open sql, conn, adOpenStatic, adLockReadOnly, adCmdText
  41. ' Get the count of the pages using the given page size
  42. iPageCount = rs.PageCount
  43. iFieldCount = rs.Fields.Count
  44. iRecordCount = rs.RecordCount
  45. ' If the request page falls outside the acceptable range,
  46. ' give them the closest match (1 or max)
  47. If iPageCurrent > iPageCount Then iPageCurrent = iPageCount
  48. If iPageCurrent < 1 Then iPageCurrent = 1
  49.  
  50. If iPageCount = 0 Then
  51.     Response.Write "No records found!"
  52. Else
  53.     ' Move to the selected page
  54.     rs.AbsolutePage = iPageCurrent
  55.  
  56.  
  57.     response.write("<a href=logout.asp><h4 align=right>LogOut</h4></a>")
  58.     response.write("<h3 align=center><u>Employee Details</u></h3>")
  59.  
  60.     ' Spacing
  61.     Response.Write vbCrLf
  62.  
  63.     ' Continue with a title row in our table
  64.     Response.Write "<table border=1 align=center>" & vbCrLf
  65.  
  66.     ' Show field names in the top row
  67.     Response.Write vbTab & "<tr>" & vbCrLf
  68.     For I = 0 To rs.Fields.Count - 1
  69.         Response.Write vbTab & vbTab & "<th>"
  70.         Response.Write rs.Fields(I).Name
  71.        Response.Write "</th>" & vbCrLf
  72.     Next 'I
  73.     Response.Write vbTab & "</tr>" & vbCrLf
  74.  
  75.     ' Loop through our records and ouput 1 row per record
  76.     iRecordsShown = 0
  77.     Do While iRecordsShown < iPageSize And Not rs.EOF
  78.         Response.Write vbTab & "<tr>" & vbCrLf
  79.         For I = 0 To rs.Fields.Count - 1
  80.             Response.Write vbTab & vbTab & "<td>"
  81.             Response.Write rs.Fields(I)
  82.             Response.Write "</td>" & vbCrLf
  83.         Next 'I
  84.         Response.Write vbTab & "</tr>" & vbCrLf
  85.  
  86.         ' Increment the number of records we've shown
  87.         iRecordsShown = iRecordsShown + 1
  88.         ' Can't forget to move to the next record!
  89.         rs.MoveNext
  90.     Loop
  91.  
  92.     ' All done - close table
  93.     Response.Write "</table>" & vbCrLf
  94. End If
  95. response.write("<br><a href=employeeadd.asp><center><b><font color=green>Insert New Employee Details</font></b></center></a>")
  96.  
  97.     rs.Close
  98.     Set rs = Nothing
  99.     conn.Close
  100.     Set conn = Nothing
  101.  
  102.  
  103. If iPageCurrent > 1 Then
  104.     %>
  105.     <a href="dbpaging_array.asp?page=<%= iPageCurrent - 1 %>">&lt;&lt; Prev</a>
  106.     <%
  107. End If
  108. ' You can also show page numbers:
  109. For I = 1 To iPageCount
  110.     If I = iPageCurrent Then
  111.         %>
  112.         <%= I %>
  113.         <%
  114.     Else
  115.         %>
  116.         <a href="dbpaging_array.asp?page=<%= I %>&order=<%= Server.URLEncode(strOrderBy) %>"><%= I %></a>
  117.         <%
  118.     End If
  119. Next 'I
  120.  
  121. If iPageCurrent < iPageCount Then
  122.     %>
  123.     <a href="dbpaging_array.asp?page=<%= iPageCurrent + 1 %>&order=<%= Server.URLEncode(strOrderBy) %>">Next &gt;&gt;</a>
  124.     <%
  125. End If
  126. %>
Aug 18 '08 #1
4 1438
DrBunchman
979 Expert 512MB
Hi ilayacute,

I presume you are talking about this piece of code:

Expand|Select|Wrap|Line Numbers
  1.     ' Show field names in the top row
  2.     Response.Write vbTab & "<tr>" & vbCrLf
  3.     For I = 0 To rs.Fields.Count - 1
  4.         Response.Write vbTab & vbTab & "<th>"
  5.         Response.Write rs.Fields(I).Name
  6.        Response.Write "</th>" & vbCrLf
  7.     Next 'I
  8.     Response.Write vbTab & "</tr>" & vbCrLf
To add a link to these headers change your code to the following:
Expand|Select|Wrap|Line Numbers
  1.     ' Show field names in the top row
  2.     Response.Write vbTab & "<tr>" & vbCrLf
  3.     For I = 0 To rs.Fields.Count - 1
  4.         Response.Write vbTab & vbTab & "<th>"
  5.         Response.Write "<a href='editpage.asp'>" & rs.Fields(I).Name & "</a>"
  6.        Response.Write "</th>" & vbCrLf
  7.     Next 'I
  8.     Response.Write vbTab & "</tr>" & vbCrLf
Let me know if this helps,

Dr B
Aug 19 '08 #2
thank u for your response Dr.Bunchman.
but i want to add link to all records in the name field.....ie in the following code

Expand|Select|Wrap|Line Numbers
  1. iRecordsShown = 0
  2.     Do While iRecordsShown < iPageSize And Not rs.EOF
  3.         Response.Write vbTab & "<tr>" & vbCrLf
  4.         For I = 0 To rs.Fields.Count - 1
  5.             Response.Write vbTab & vbTab & "<td>"
  6.             Response.Write rs.Fields(I)
  7.             Response.Write "</td>" & vbCrLf
  8.         Next 'I
  9.         Response.Write vbTab & "</tr>" & vbCrLf
  10.  
  11.         ' Increment the number of records we've shown
  12.         iRecordsShown = iRecordsShown + 1
  13.         ' Can't forget to move to the next record!
  14.         rs.MoveNext
  15.     Loop
help me....
Aug 19 '08 #3
DrBunchman
979 Expert 512MB
Just add the anchor tag around the line as I did in my first reply. Like this:
Expand|Select|Wrap|Line Numbers
  1.  Response.Write "<a href='editpage.asp'>" & rs.Fields(I) & "</a>"
Is that what you wanted?

Dr B

PS Please don't forget to wrap your code in CODE tags - it makes your posts much easier to read - and please read the Posting Guidelines if you have not done so already. Thanks.
Aug 19 '08 #4
thanks for clue sorry for asking again i want link only 'name' that is field(1)
i tried the following but it will create link to all the records in the table.please


Expand|Select|Wrap|Line Numbers
  1. <%
  2. iRecordsShown = 0
  3.     Do While iRecordsShown < iPageSize And Not rs.EOF
  4.         Response.Write vbTab & "<tr>" & vbCrLf
  5.         For I = 0 To rs.Fields.Count - 1
  6.             Response.Write vbTab & vbTab & "<td>"
  7.           Response.Write "<a href='emp_edit.asp'>" & rs.Fields(1) & "</a>"
  8.           Response.Write  rs.Fields(I) 
  9.             Response.Write "</td>" & vbCrLf
  10.  
  11.         Next 'I
  12.         Response.Write vbTab & "</tr>" & vbCrLf
  13.  
  14.         ' Increment the number of records we've shown
  15.         iRecordsShown = iRecordsShown + 1
  16.         ' Can't forget to move to the next record!
  17.         rs.MoveNext
  18.     Loop
  19.  
  20.     ' All done - close table
  21.     Response.Write "</table>" & vbCrLf
  22. End If
  23. %>
Aug 19 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: ste | last post by:
Hi there, Further to my recent posts where I've received excellent help from Rik and Jerry, I've ended up with an image gallery on my website that displays images in a table, 3 images per row. ...
1
by: shalini jain | last post by:
Hi, I want to know how can we do pagination using XSL. There are number of tutorials available on pagination using PHP but nothing with XSL. i am really stuck with my code. Below is the code that...
16
by: gnawz | last post by:
I have a pagination function I am using in a file called functions.php as below<? //Pagination functions function getPagingQuery($sql, $itemPerPage = 10) { if (isset($_GET) && (int)$_GET > 0) ...
4
by: ArizonaJohn | last post by:
Hello, The code below works great. The user enters a name into an HTML form, the code looks up a table with that name, and then that table is displayed. I am trying to use pagination with it,...
2
by: kkshansid | last post by:
this is my search page on which i am getting two parameters from previous page but the problem is that as soon as i click any other next pages my sql query fails as it doesnt get these two parameters...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.