473,586 Members | 2,702 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

asp pagination help

17 New Member
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 1444
DrBunchman
979 Recognized Expert Contributor
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
ilayacute
17 New Member
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 Recognized Expert Contributor
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
ilayacute
17 New Member
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
2757
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. This works great and opens all images in the database when I open the url mywebsite/gallery.php, or I can choose certain images (by category) by...
1
6841
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 i have written for pagination but it displays the link of all the pages at one go i.e. if i have 8 pages showing 10 results per page than it shows...
16
2758
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) { $page = (int)$_GET; } else { $page = 1; } // start fetching from this row number $offset = ($page - 1) *...
4
3562
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, and the pagination almost works. The first page of the pagination works fine, but when I click on one of the links for one of the next pages, the...
2
2586
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 kindly help <?php session_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
0
7911
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8200
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8215
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6610
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3836
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1179
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.