• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1417
  • Last Modified:

How can we display records using <prev> and <next> button?

Hi

I am displaying the recods in tabular format..
when I clik on the Itemid ,it will redirect the page to edit screen and display the selected id values in text box.

I am adding next and previous buttons on the screen.. if I click on next button it should display a next record. If we click on previous button it should display a previous record on text box...

which is the best way to proceed/
Can any one give some logic to do  this?
0
lucky20
Asked:
lucky20
  • 9
  • 9
3 Solutions
 
sammySeltzerCommented:
How good are you at modifying codes?

I have a working version but a bit complicated.

However, try this one on this link.

The very first one, I understand works you just change the link that says Print to Edit.

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/ASP/Q_26288302.html?sfQueryTermInfo=1+10+30+asp+classic+page

Let me know if you want my version or you need help with this version.

0
 
lucky20Author Commented:
@sammyseltzer

thanks for the link..
But in very first post, that code is in dot net..

i am not that much good in modifing..

If u have any thing in classic asp plz share with me.. That would be helpful..
 
0
 
lucky20Author Commented:
This is how my screen looks like...I have written code for "Save" and "Delete" button..

when user clicks on "Next" button it should display next record,when he clicks on "Prev"  button it should display previous record.

I  need someone help here to get the previous and next records when those button clicks..

Region.png
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
sammySeltzerCommented:
so, this is basically what you wanted?

Are you using sql server or access db?

Also, are the fieldnames called Id and Name?

Is id a number data type?
0
 
lucky20Author Commented:


Yes exactly I need like this.(only prev,Next)
I am using Sqlserver2005
yes field names are Id,Name

Id is an integer
0
 
sammySeltzerCommented:
Ok, will be back shortly.
0
 
lucky20Author Commented:
sure..
0
 
sammySeltzerCommented:
Ok, here you go. It works because I tested it.

See below for more comments.

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>

<%
set objConn = server.CreateObject("ADODB.Connection")
objConn.ConnectionString= "Provider=microsoft.jet.oledb.4.0;Data source=" & server.mappath("Paging.mdb")
objConn.Open

' ***********************************************************************
' ***********************************************************************
'
' Process postback requests from this page
'
' ***********************************************************************
' ***********************************************************************

If Trim("" & Request.Form("POSTBACK")) = "YES" Then
	' get all the expected form fields
	IdNumber			= Request.Form("IdNumber")
	theName				= Request.Form("theName")

	' process form submittal back to ourselves, if any
	If Trim(Request.Form("SAVE")) = "Save!" Then
		' save changes to existing table

		SQL	= "Update pagingTable SET " _
			 & "Name= '" & theName & "' " _
			 & " where ID=" & IdNumber
          'Response.Write "DEBUG: " & SQL & "<HR>"
          'Response.End
         objConn.Execute SQL

	Elseif Trim(Request.Form("DELETE")) = "Delete!" Then
         SQL = "DELETE FROM pagingTable " _
			 & " where Id=" & IdNumber
          Response.Write "DEBUG: " & SQL & "<HR>"
          Response.End
		 objConn.Execute SQL
     End If
  End If
' end of handling postback=yes
' ***********************************************************************
' ***********************************************************************
' End Of Handling Postbacks
' ***********************************************************************
' ***********************************************************************

dim objRs,objConn,strSql
set objRS =server.CreateObject("ADODB.Recordset")
set objConn = server.CreateObject("ADODB.Connection")
objConn.ConnectionString= "Provider=microsoft.jet.oledb.4.0;Data source=" & server.mappath("Paging.mdb")
objRs.CursorLocation = 3
objConn.Open
strSql ="select * from pagingtable"
objRs.Open strSql,objConn,3,2
objRs.PageSize =1
dim strColor,intCount
intCount = 1


%>
<form name=form1 action="paging.asp?" method=post>
<input type=hidden name="POSTBACK" value="YES">
<table>
<%
dim lngPage
lngPage = cint(Request.QueryString("Page"))
if lngPage < 1 then
    lngPage = 1
end if
objRs.AbsolutePage = lngPage
while objRs.AbsolutePage = lngPage
if intCount mod 2 = 0 then
    strColor= "eeeeee"
else
    strColor="ffffff"
end if
%>
    <tr bgcolor=<%=strColor%>>
        <td><b>EmpNo</b></td>
        <td><b><input name="idNumber" STYLE="background-color:#AFEAAA" value="<%=objRs(0)%>"></b></td>
    </tr>
    <tr>
      <td><b>EName</b></td>
      <td><b><input name="theName" STYLE="background-color:#AFEAAA" value="<%=objRs(1)%>"></b></td>
    </tr>
<%objRs.MoveNext
intCount = intCount + 1
wend%>

<%
lngPage = cint(Request.QueryString("Page"))
    if lngpage < 1 then
        lngpage =1
    end if
objRs.AbsolutePage = lngPage
%>
<tr>
    <td colspan=3 align=left>
        <%if objRs.AbsolutePage <> 1 then %>
        <a href=paging.asp?Page=<%=objRs.AbsolutePage - 1%>><img src="images/previous.gif" border="0" alt="Previous"></a>
        <%end if%>
        <%if objRs.AbsolutePage <> objRs.PageCount and objRs.AbsolutePage <> objRs.PageCount - 1 then %>
        <a href=paging.asp?Page=<%=objRs.AbsolutePage + 1%>><img src="images/next.gif" border="0"  alt="Next"></a>
        <%end if%>
    </td>
     <td><input type="Submit" style="font-size: x-small; font-weight: bold; background-color:silver;width:65px;" name="SAVE" value="Save!"></td>
     <td><input type="Submit" style="font-size: x-small; font-weight: bold; background-color:silver;width:65px;" name="DELETE" value="Delete!"></td>
</tr>

</table>
</form>
</BODY>
</HTML>

Open in new window


Some items to note.
 It doesn't have an Add New Record feature. You will have to add that following my example if you don't already have that. I gave you the ability to edit records and to delete. If I understand, that's what you asked for.

You can page Next/Previous.

No need to add A Previous button there although you could if you really need to see it there.

You will have to connection string to sql server. I used Access for testing.

If you need help there, let me know.

Also, I created a couple of buttons, one for Previous and the other for Next.

You can download them as they are attached.

Finally, you will have to rearrange the Save/Delete/Next/Previous buttons as my boss is all over my shoulders.

Here is the access db for testing.

Let me know if you have any questions.

Good luck
Previous.gif
next.gif
Paging.mdb
0
 
sammySeltzerCommented:
Please replace  this:

<tr>
    <td colspan=3 align=left>
        <%if objRs.AbsolutePage <> 1 then %>
        <a href=paging.asp?Page=<%=objRs.AbsolutePage - 1%>><img src="images/previous.gif" border="0" alt="Previous"></a>
        <%end if%>
        <%if objRs.AbsolutePage <> objRs.PageCount and objRs.AbsolutePage <> objRs.PageCount - 1 then %>
        <a href=paging.asp?Page=<%=objRs.AbsolutePage + 1%>><img src="images/next.gif" border="0"  alt="Next"></a>
        <%end if%>
    </td>
     <td><input type="Submit" style="font-size: x-small; font-weight: bold; background-color:silver;width:65px;" name="SAVE" value="Save!"></td>
     <td><input type="Submit" style="font-size: x-small; font-weight: bold; background-color:silver;width:65px;" name="DELETE" value="Delete!"></td>
</tr>

Open in new window


with this:

<tr>
     <td><input type="Submit" style="font-size: x-small; font-weight: bold; background-color:silver;width:65px;" name="SAVE" value="Save!"></td>
    <td colspan=3 align=left>
        <%if objRs.AbsolutePage <> 1 then %>
        <a href=paging.asp?Page=<%=objRs.AbsolutePage - 1%>><img src="images/previous.gif" border="0" alt="Previous"></a>
        <%end if%>
        <%if objRs.AbsolutePage <> objRs.PageCount and objRs.AbsolutePage <> objRs.PageCount - 1 then %>
        <a href=paging.asp?Page=<%=objRs.AbsolutePage + 1%>><img src="images/next.gif" border="0"  alt="Next"></a>
        <%end if%>
    </td>
     <td><input type="Submit" style="font-size: x-small; font-weight: bold; background-color:silver;width:65px;" name="DELETE" value="Delete!"></td>
</tr>

Nothing wrong in terms of the way it works.

I just changed the layout a bit.
0
 
sammySeltzerCommented:
Last change, sorry.

replace this delete button:
  <td><input type="Submit" style="font-size: x-small; font-weight: bold; background-color:silver;width:65px;" name="DELETE" value="Delete!"></td>

with this:

     <td><input type="Submit" style="font-size: x-small; font-weight: bold; background-color:silver;width:65px;" onclick="return confirm('Are you sure you really want to delete this record?');" name="DELETE" value="Delete!"></td>

I wanted your users to be warned before they delete an item.
0
 
lucky20Author Commented:
@sammySeltzer

there is no changes in your code.. This is how I needed..

I am using your code with out making any mdofications.,..

Thanks a lot..
I never got quick response to my question...

http://localhost/sample/paging.asp?Page=2
can we hide number in  page=2 (page=#)
0
 
lucky20Author Commented:
@sammySeltzer
thanks a lot for quick reply..
0
 
oaksongCommented:
Most IDE's today provide that as a "built in" service. That is, when you add certain controls that should have the capability, when you check the Properties, you'll find that it's provided. You neglect to mention which IDE you are working in.
0
 
lucky20Author Commented:
@oaksong
sorry ..I didn't understand what are talking..

If you see my tags you can understand..it is classic ASP.

@sammySeltzer

I have tried so many times.. but it is not displaying last record.
(if I have 10 records in my table.. It is not displaying 10th record).

can you check this once.
thanks
0
 
sammySeltzerCommented:
Then we are going to add a couple more controls, First and Last which means that you will have to create two more buttons, one for First and one for Last.

Perhaps, I tested with 3 recors only?

Here is a modified code.

<tr>
     <td><input type="Submit" style="font-size: x-small; font-weight: bold; background-color:silver;width:65px;" name="SAVE" value="Save!"></td>
    <td colspan=3 align=left>
        <%if objRs.AbsolutePage <> 1 then %>
         <a href=paging.asp?Page=1>First</a>
        <%end if%>
        <%if objRs.AbsolutePage <> 1 and objRs.AbsolutePage <> 2 then %>
        <a href=paging.asp?Page=<%=objRs.AbsolutePage - 1%>><img src="images/previous.gif" border="0" alt="Previous"></a>
        <%end if%>
        <%if objRs.AbsolutePage <> objRs.PageCount and objRs.AbsolutePage <> objRs.PageCount - 1 then %>
        <a href=paging.asp?Page=<%=objRs.AbsolutePage + 1%>><img src="images/next.gif" border="0"  alt="Next"></a>
        <%end if%>
        <%if objRs.AbsolutePage <> objRs.PageCount then%>
        <a href=paging.asp?Page=<%=objRs.PageCount %>>Last</a>
        <%end if%>
    </td>
     <td><input type="Submit" style="font-size: x-small; font-weight: bold; background-color:silver;width:65px;" onclick="return confirm('Are you sure you really want to delete this record?');" name="DELETE" value="Delete!"></td>
</tr>

Open in new window


@oaksong, bear in mind that this is classic ASP. If you are talking about Dreamweaver or Frontpage, they are worth more trouble than it is necessary.
0
 
lucky20Author Commented:
@sammy

thanks for giving modified code..

But now my page is with full of buttons and links.. I didn't like the screen...

is it possible with out adding first and last,
can't we use just previous and next to display until last record appears.


Thank you so much.
0
 
lucky20Author Commented:
0
 
sammySeltzerCommented:
let me test this. I don't have access to the code I sent you yesterday.

So, I am going to have to download stuff from here and test.

Be back shortly...
0
 
sammySeltzerCommented:
Ok, here. Replace this:

<tr>
     <td><input type="Submit" style="font-size: x-small; font-weight: bold; background-color:silver;width:65px;" name="SAVE" value="Save!"></td>
    <td colspan=3 align=left>
        <%if objRs.AbsolutePage <> 1 then %>
         <a href=paging.asp?Page=1>First</a>
        <%end if%>
        <%if objRs.AbsolutePage <> 1 and objRs.AbsolutePage <> 2 then %>
        <a href=paging.asp?Page=<%=objRs.AbsolutePage - 1%>><img src="images/previous.gif" border="0" alt="Previous"></a>
        <%end if%>
        <%if objRs.AbsolutePage <> objRs.PageCount and objRs.AbsolutePage <> objRs.PageCount - 1 then %>
        <a href=paging.asp?Page=<%=objRs.AbsolutePage + 1%>><img src="images/next.gif" border="0"  alt="Next"></a>
        <%end if%>
        <%if objRs.AbsolutePage <> objRs.PageCount then%>
        <a href=paging.asp?Page=<%=objRs.PageCount %>>Last</a>
        <%end if%>
    </td>
     <td><input type="Submit" style="font-size: x-small; font-weight: bold; background-color:silver;width:65px;" onclick="return confirm('Are you sure you really want to delete this record?');" name="DELETE" value="Delete!"></td>
</tr> 

Open in new window


WITH This:

<tr>
     <td><input type="Submit" style="font-size: x-small; font-weight: bold; background-color:silver;width:65px;" name="SAVE" value="Save!"></td>
    <td colspan=3 align=left>
        <%if objRs.AbsolutePage <> 1 then %>
        <a href=paging.asp?Page=<%=objRs.AbsolutePage - 1%>><img src="images/previous.gif" border="0" alt="Previous"></a>
        <%end if%>
        <%if objRs.AbsolutePage <> objRs.PageCount then %>
        <a href=paging.asp?Page=<%=objRs.AbsolutePage + 1%>><img src="images/next.gif" border="0"  alt="Next"></a>
        <%end if%>
    </td>
     <td><input type="Submit" style="font-size: x-small; font-weight: bold; background-color:silver;width:65px;" onclick="return confirm('Are you sure you really want to delete this record?');" name="DELETE" value="Delete!"></td>

</tr>

Open in new window


and you should be fine.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 9
  • 9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now