|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
hey
i hope to get help in retriving data from sql using paging in asp code. hope someone out there can help me out. thanks jenice |
|
#2
|
|||
|
|||
|
Hi,
Try this code <!-- #include file="adovbs.inc" --> <% Dim iPageSize 'How big our pages are Dim iPageCount 'The number of pages we get back Dim iPageCurrent 'The page we want to show Dim iRecordsShown 'Loop controller for displaying just iPageSize records iPageSize = 5 If Request.QueryString("p") = "" Then iPageCurrent = 1 Else iPageCurrent = CInt(Request.QueryString("p")) End If Set oConn = server.createObject("ADODB.Connection") sDSN = "DRIVER={SQL Server};SERVER=yourservername;UID=uid;PWD=pwd" oConn.open sDSN Set oRS=server.createobject("adodb.recordset") oRS.PageSize = iPageSize oRS.CacheSize = iPageSize oRS.Open "select * from temptable",oConn,adOpenStatic, adLockReadOnly, adCmdText %> <html> <head> </head> <body> <% iPageCount = oRS.PageCount If iPageCurrent > iPageCount Then iPageCurrent = iPageCount If iPageCurrent < 1 Then iPageCurrent = 1 If not iPageCount = 0 Then oRS.AbsolutePage = iPageCurrent iRecordsShown = 0 Do While iRecordsShown < iPageSize And Not oRS.EOF response.write oRS.fields(0)&"<br>" ' You can format the table here I am just displaying one field iRecordsShown = iRecordsShown + 1 oRS.movenext Loop If iPageCurrent > 1 Then %> <a href="trial.asp?p=<%= iPageCurrent - 1 %>"><< Prev</a> <% End If For I = 1 To iPageCount If I = iPageCurrent Then %> <%= I %> <%Else%> <a href="trial.asp?p=<%= I %>"><%= I %></a> <% End If Next 'I If iPageCurrent < iPageCount Then %> <a href="m_list.asp?p=<%= iPageCurrent + 1 %>">Next >></a> <%End If%> </body> </html> You require the adovbs.inc file however for this code. C'ya Savage |
![]() |
| Viewing: Dev Shed Forums > Other > Beginner Programming > paging in asp |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|