|
 |
asp_web_howto thread: paging recordset
Message #1 by nusrat sarwar <nusratsarwar@y...> on Tue, 22 Jan 2002 10:55:24 -0800 (PST)
|
|
Hi all
Hope you all are fine and well
now my issue:
I have to see 4 records per page and my paging ASP is
doing it.
I am selecting name according to letters selected in
"name.html"
for example if I select "D" the paging ASP has to
bring recordset only of names starting from letter D.
the problem is the paging ASP shows first 4 records of
names starting from "D" but when I click to "Next" it
start showing names from letter "A"
why is this so.?
what is wrong ?
how can I deal with the problem?
please do let me know as soon as possible
many many thanx in advance
regards
nusrat
__________________________________________________
Do You Yahoo!?
Send FREE video emails in Yahoo! Mail!
http://promo.yahoo.com/videomail/
Message #2 by Joe Ingle <Joe@k...> on Tue, 22 Jan 2002 20:53:23 -0000
|
|
It will have to do with the querystring your using to view the next part of
the recordset. It sounds like you've left off the query parameter.
-----Original Message-----
From: nusrat sarwar [mailto:nusratsarwar@y...]
Sent: Tuesday, January 22, 2002 06:55
To: ASP Web HowTo
Subject: [asp_web_howto] paging recordset
Hi all
Hope you all are fine and well
now my issue:
I have to see 4 records per page and my paging ASP is
doing it.
I am selecting name according to letters selected in
"name.html"
for example if I select "D" the paging ASP has to
bring recordset only of names starting from letter D.
the problem is the paging ASP shows first 4 records of
names starting from "D" but when I click to "Next" it
start showing names from letter "A"
why is this so.?
what is wrong ?
how can I deal with the problem?
please do let me know as soon as possible
many many thanx in advance
regards
nusrat
__________________________________________________
Do You Yahoo!?
Send FREE video emails in Yahoo! Mail!
http://promo.yahoo.com/videomail/
$subst('Email.Unsub').
Message #3 by <sathish297@y...> on Wed, 23 Jan 2002 10:31:55 +0530
|
|
Hi,
1) Change the query and include ' % X % ' in the where clause.
2) Include ' X ' in the href for the link 'next'
** 3) You have to pass the 'X' to every page. **
With Regards,
R. Sathish Kumar
sathish297@y...
----- Original Message -----
From: "nusrat sarwar" <nusratsarwar@y...>
To: "ASP Web HowTo" <asp_web_howto@p...>
Sent: Wednesday, January 23, 2002 12:25 AM
Subject: [asp_web_howto] paging recordset
> Hi all
> Hope you all are fine and well
> now my issue:
> I have to see 4 records per page and my paging ASP is
> doing it.
>
> I am selecting name according to letters selected in
> "name.html"
> for example if I select "D" the paging ASP has to
> bring recordset only of names starting from letter D.
> the problem is the paging ASP shows first 4 records of
> names starting from "D" but when I click to "Next" it
> start showing names from letter "A"
> why is this so.?
> what is wrong ?
> how can I deal with the problem?
> please do let me know as soon as possible
> many many thanx in advance
> regards
> nusrat
>
>
> __________________________________________________
> Do You Yahoo!?
> Send FREE video emails in Yahoo! Mail!
> http://promo.yahoo.com/videomail/
>
$subst('Email.Unsub').
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
Message #4 by nusrat sarwar <nusratsarwar@y...> on Wed, 23 Jan 2002 10:50:24 -0800 (PST)
|
|
Hi
many thanx Sathish Kumar and Joe for help
I'll try and see ,sure that it will work out
anyway take care
regards
nusrat
--- sathish297@y... wrote:
> Hi,
>
> 1) Change the query and include ' % X % ' in the
> where clause.
> 2) Include ' X ' in the href for the link 'next'
> ** 3) You have to pass the 'X' to every page. **
>
> With Regards,
> R. Sathish Kumar
> sathish297@y...
>
>
>
> ----- Original Message -----
> From: "nusrat sarwar" <nusratsarwar@y...>
> To: "ASP Web HowTo" <asp_web_howto@p...>
> Sent: Wednesday, January 23, 2002 12:25 AM
> Subject: [asp_web_howto] paging recordset
>
>
> > Hi all
> > Hope you all are fine and well
> > now my issue:
> > I have to see 4 records per page and my paging ASP
> is
> > doing it.
> >
> > I am selecting name according to letters selected
> in
> > "name.html"
> > for example if I select "D" the paging ASP has to
> > bring recordset only of names starting from letter
> D.
> > the problem is the paging ASP shows first 4
> records of
> > names starting from "D" but when I click to "Next"
> it
> > start showing names from letter "A"
> > why is this so.?
> > what is wrong ?
> > how can I deal with the problem?
> > please do let me know as soon as possible
> > many many thanx in advance
> > regards
> > nusrat
> >
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Send FREE video emails in Yahoo! Mail!
> > http://promo.yahoo.com/videomail/
> >
> $subst('Email.Unsub').
>
>
>
>
_________________________________________________________
>
> Do You Yahoo!?
>
> Get your free @yahoo.com address at
> http://mail.yahoo.com
>
>
>
>
$subst('Email.Unsub').
__________________________________________________
Do You Yahoo!?
Send FREE video emails in Yahoo! Mail!
http://promo.yahoo.com/videomail/
Message #5 by nusrat sarwar <nusratsarwar@y...> on Thu, 24 Jan 2002 10:38:54 -0800 (PST)
|
|
Hi Sathish Kumar.
I am sending you my code (paging ASP)
see what I should do
as you said I did and it gave me required result but
when I am giving variable in querystring it is not
working please help me out
many thanx
regards
nusrat
<%' BEGIN USER CONSTANTS
Dim CONN_STRING
Dim CONN_USER
Dim CONN_PASS
CONN_USER = ""
CONN_PASS = ""
CONN_STRING = Application("SQLConnString")
CONN_USER = Application("SQLUsername")
CONN_PASS = Application("SQLPassword")
Dim iPageSize
Dim iPageCount
Dim iPageCurrent
Dim strOrderBy
Dim strSQL
Dim objPagingConn
Dim objPagingRS
Dim iRecordsShown
Dim I
'variable to hold chosen letter A-Z from list box
qs2=Request.Form("lttrs")
iPageSize = 4
If Request.QueryString("page") = "" Then
iPageCurrent = 1
Else iPageCurrent = CInt(Request.QueryString("page"))
End If
If Request.QueryString("qs2") = "" Then
strOrderBy = "babyid"
Else
strOrderBy = Request.QueryString("qs2")
End If
strSQL = "SELECT babyname,bnmean FROM babynames where
babycat='female' and babyname like '"&qs2&"%' ORDER BY
babyname asc" '& strOrderBy & ";"
"&qs2&"%
Set objPagingConn
Server.CreateObject("ADODB.Connection")
objPagingConn.Open "DBQ=" &
Server.Mappath("babynames.mdb") & ";Driver={Microsoft
Access Driver (*.mdb)};"
Set objPagingRS
Server.CreateObject("ADODB.Recordset")
objPagingRS.PageSize = iPageSize
objPagingRS.CacheSize = iPageSize
objPagingRS.Open strSQL , objPagingConn ,
adOpenStatic, adLockReadOnly , adCmdText '50
iPageCount = objPagingRS.PageCount
If iPageCurrent > iPageCount Then iPageCurrent
iPageCount
If iPageCurrent < 1 Then iPageCurrent = 1
If iPageCount = 0 Then
Response.Write "No records found!"
Else
objPagingRS.AbsolutePage = iPageCurrent
%>
<FONT SIZE="+1">
Page <B>
<%= iPageCurrent
%>
</B> of <B>
<%= iPageCount
%>
</B>
</FONT>
<%
response.write qs2
' Spacing
Response.Write "<BR><BR>" & vbCrLf
' Continue with a title row in our table
Response.Write "<TABLE BORDER=""1"">" & vbCrLf
' Show field names in the top row
Response.Write vbTab & "<TR>" & vbCrLf
For I = 0 To objPagingRS.Fields.Count - 1
Response.Write vbTab & vbTab & "<TD><B>"
Response.Write objPagingRS.Fields(I).Name
Response.Write "<B></TD>" & vbCrLf
Next 'I
Response.Write vbTab & "</TR>" & vbCrLf
' Loop through our records and ouput 1 row per record
iRecordsShown = 0
Do While iRecordsShown < iPageSize And Not
objPagingRS.EOF
Response.Write vbTab & "<TR>" & vbCrLf
For I = 0 To objPagingRS.Fields.Count - 1
Response.Write vbTab & vbTab & "<TD>"
Response.Write objPagingRS.Fields(I)
Response.Write "</TD>" & vbCrLf
Next 'I
Response.Write vbTab & "</TR>" & vbCrLf
' Increment the number of records we've shown
iRecordsShown = iRecordsShown + 1 ' Can't forget to
move to the next record!
objPagingRS.MoveNext
Loop ' All done - close table
Response.Write "</TABLE>" & vbCrLf
End If
If iPageCurrent <> 1 Then
%>
<A HREF="./gnames.asp?page=<%= iPageCurrent - 1
%>&qs2=<%= Server.URLEncode(strOrderBy)
%>">Previous</A>
<%
' Above spacing is inside the If so we don't get it
unless needed
End If
If iPageCurrent < iPageCount Then
%>
<A HREF="./gnames.asp?page=<%= iPageCurrent + 1
%>&qs2=<%= Server.URLEncode(strOrderBy) %>">Next</A>
<% End If ' END RUNTIME CODE
%>
__________________________________________________
Do You Yahoo!?
Great stuff seeking new owners in Yahoo! Auctions!
http://auctions.yahoo.com
Message #6 by "Zaragoza, Enzo" <enzaux@g...> on Fri, 25 Jan 2002 03:31:10 +0800
|
|
This is a multi-part message in MIME format.
------=_NextPart_000_0029_01C1A550.BBA1BBB0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hi guys!! Just wanna ask, where is paging recordset used?
Thanks,
Enzo :)
----- Original Message -----
From: nusrat sarwar
To: ASP Web HowTo
Sent: Friday, January 25, 2002 2:38 AM
Subject: [asp_web_howto] RE: paging recordset
Hi Sathish Kumar.
I am sending you my code (paging ASP)
see what I should do
as you said I did and it gave me required result but
when I am giving variable in querystring it is not
working please help me out
many thanx
regards
nusrat
<%' BEGIN USER CONSTANTS
Dim CONN_STRING
Dim CONN_USER
Dim CONN_PASS
CONN_USER =3D ""
CONN_PASS =3D ""
CONN_STRING =3D Application("SQLConnString")
CONN_USER =3D Application("SQLUsername")
CONN_PASS =3D Application("SQLPassword")
Dim iPageSize
Dim iPageCount
Dim iPageCurrent
Dim strOrderBy
Dim strSQL
Dim objPagingConn
Dim objPagingRS
Dim iRecordsShown
Dim I
'variable to hold chosen letter A-Z from list box
qs2=3DRequest.Form("lttrs")
iPageSize =3D 4
If Request.QueryString("page") =3D "" Then
iPageCurrent =3D 1
Else iPageCurrent =3D CInt(Request.QueryString("page"))
End If
If Request.QueryString("qs2") =3D "" Then
strOrderBy =3D "babyid"
Else
strOrderBy =3D Request.QueryString("qs2")
End If
strSQL =3D "SELECT babyname,bnmean FROM babynames where
babycat=3D'female' and babyname like '"&qs2&"%' ORDER BY
babyname asc" '& strOrderBy & ";"
"&qs2&"%
Set objPagingConn =3D
Server.CreateObject("ADODB.Connection")
objPagingConn.Open "DBQ=3D" &
Server.Mappath("babynames.mdb") & ";Driver=3D{Microsoft
Access Driver (*.mdb)};"
Set objPagingRS =3D
Server.CreateObject("ADODB.Recordset")
objPagingRS.PageSize =3D iPageSize
objPagingRS.CacheSize =3D iPageSize
objPagingRS.Open strSQL , objPagingConn ,
adOpenStatic, adLockReadOnly , adCmdText '50
iPageCount =3D objPagingRS.PageCount
If iPageCurrent > iPageCount Then iPageCurrent =3D
iPageCount
If iPageCurrent < 1 Then iPageCurrent =3D 1
If iPageCount =3D 0 Then
Response.Write "No records found!"
Else
objPagingRS.AbsolutePage =3D iPageCurrent
%>
<FONT SIZE=3D"+1">
Page <B>
<%=3D iPageCurrent
%>
</B> of <B>
<%=3D iPageCount
%>
</B>
</FONT>
<%
response.write qs2
' Spacing
Response.Write "<BR><BR>" & vbCrLf
' Continue with a title row in our table
Response.Write "<TABLE BORDER=3D""1"">" & vbCrLf
' Show field names in the top row
Response.Write vbTab & "<TR>" & vbCrLf
For I =3D 0 To objPagingRS.Fields.Count - 1
Response.Write vbTab & vbTab & "<TD><B>"
Response.Write objPagingRS.Fields(I).Name
Response.Write "<B></TD>" & vbCrLf
Next 'I
Response.Write vbTab & "</TR>" & vbCrLf
' Loop through our records and ouput 1 row per record
iRecordsShown =3D 0
Do While iRecordsShown < iPageSize And Not
objPagingRS.EOF
Response.Write vbTab & "<TR>" & vbCrLf
For I =3D 0 To objPagingRS.Fields.Count - 1
Response.Write vbTab & vbTab & "<TD>"
Response.Write objPagingRS.Fields(I)
Response.Write "</TD>" & vbCrLf
Next 'I
Response.Write vbTab & "</TR>" & vbCrLf
' Increment the number of records we've shown
iRecordsShown =3D iRecordsShown + 1 ' Can't forget to
move to the next record!
objPagingRS.MoveNext
Loop ' All done - close table
Response.Write "</TABLE>" & vbCrLf
End If
If iPageCurrent <> 1 Then
%>
<A HREF=3D"./gnames.asp?page=3D<%=3D iPageCurrent - 1
%>&qs2=3D<%=3D Server.URLEncode(strOrderBy)
%>">Previous</A>
<%
' Above spacing is inside the If so we don't get it
unless needed
End If
If iPageCurrent < iPageCount Then
%>
<A HREF=3D"./gnames.asp?page=3D<%=3D iPageCurrent + 1
%>&qs2=3D<%=3D Server.URLEncode(strOrderBy) %>">Next</A>
<% End If ' END RUNTIME CODE
%>
__________________________________________________
Do You Yahoo!?
Great stuff seeking new owners in Yahoo! Auctions!
http://auctions.yahoo.com
$subst('Email.Unsub').
Message #7 by <sathish297@y...> on Fri, 25 Jan 2002 09:53:34 +0530
|
|
Hi nusrat,
I made a small modification in your code.
'variable to hold chosen letter A-Z from list box
if Request.Form("lttrs")<>"" then
qs2=Request.Form("lttrs")
elseif Request.QueryString("qs2")<>"" then
qs2=Request.QueryString("qs2")
end if
You know where it occurs. Please replace that line with the above code and
see.
It works.
With Regards,
R. Sathish Kumar
sathish297@y...
----- Original Message -----
From: "nusrat sarwar" <nusratsarwar@y...>
To: "ASP Web HowTo" <asp_web_howto@p...>
Sent: Friday, January 25, 2002 12:08 AM
Subject: [asp_web_howto] RE: paging recordset
> Hi Sathish Kumar.
> I am sending you my code (paging ASP)
> see what I should do
> as you said I did and it gave me required result but
> when I am giving variable in querystring it is not
> working please help me out
> many thanx
> regards
> nusrat
>
>
>
> <%' BEGIN USER CONSTANTS
> Dim CONN_STRING
> Dim CONN_USER
> Dim CONN_PASS
>
> CONN_USER = ""
> CONN_PASS = ""
>
> CONN_STRING = Application("SQLConnString")
> CONN_USER = Application("SQLUsername")
> CONN_PASS = Application("SQLPassword")
>
> Dim iPageSize
> Dim iPageCount
> Dim iPageCurrent
> Dim strOrderBy
> Dim strSQL
> Dim objPagingConn
> Dim objPagingRS
> Dim iRecordsShown
> Dim I
>
> 'variable to hold chosen letter A-Z from list box
>
> qs2=Request.Form("lttrs")
> iPageSize = 4
>
> If Request.QueryString("page") = "" Then
> iPageCurrent = 1
> Else iPageCurrent = CInt(Request.QueryString("page"))
> End If
>
>
> If Request.QueryString("qs2") = "" Then
> strOrderBy = "babyid"
> Else
> strOrderBy = Request.QueryString("qs2")
> End If
>
> strSQL = "SELECT babyname,bnmean FROM babynames where
> babycat='female' and babyname like '"&qs2&"%' ORDER BY
> babyname asc" '& strOrderBy & ";"
> "&qs2&"%
>
>
> Set objPagingConn
> Server.CreateObject("ADODB.Connection")
> objPagingConn.Open "DBQ=" &
> Server.Mappath("babynames.mdb") & ";Driver={Microsoft
> Access Driver (*.mdb)};"
>
> Set objPagingRS
> Server.CreateObject("ADODB.Recordset")
> objPagingRS.PageSize = iPageSize
>
> objPagingRS.CacheSize = iPageSize
> objPagingRS.Open strSQL , objPagingConn ,
> adOpenStatic, adLockReadOnly , adCmdText '50
>
> iPageCount = objPagingRS.PageCount
> If iPageCurrent > iPageCount Then iPageCurrent
> iPageCount
> If iPageCurrent < 1 Then iPageCurrent = 1
>
> If iPageCount = 0 Then
> Response.Write "No records found!"
> Else
>
> objPagingRS.AbsolutePage = iPageCurrent
>
> %>
> <FONT SIZE="+1">
> Page <B>
> <%= iPageCurrent
> %>
> </B> of <B>
> <%= iPageCount
> %>
> </B>
> </FONT>
> <%
> response.write qs2
> ' Spacing
> Response.Write "<BR><BR>" & vbCrLf
> ' Continue with a title row in our table
> Response.Write "<TABLE BORDER=""1"">" & vbCrLf
> ' Show field names in the top row
> Response.Write vbTab & "<TR>" & vbCrLf
> For I = 0 To objPagingRS.Fields.Count - 1
> Response.Write vbTab & vbTab & "<TD><B>"
> Response.Write objPagingRS.Fields(I).Name
> Response.Write "<B></TD>" & vbCrLf
> Next 'I
> Response.Write vbTab & "</TR>" & vbCrLf
> ' Loop through our records and ouput 1 row per record
>
> iRecordsShown = 0
> Do While iRecordsShown < iPageSize And Not
> objPagingRS.EOF
> Response.Write vbTab & "<TR>" & vbCrLf
> For I = 0 To objPagingRS.Fields.Count - 1
> Response.Write vbTab & vbTab & "<TD>"
> Response.Write objPagingRS.Fields(I)
> Response.Write "</TD>" & vbCrLf
> Next 'I
> Response.Write vbTab & "</TR>" & vbCrLf
> ' Increment the number of records we've shown
> iRecordsShown = iRecordsShown + 1 ' Can't forget to
> move to the next record!
> objPagingRS.MoveNext
> Loop ' All done - close table
>
> Response.Write "</TABLE>" & vbCrLf
> End If
>
> If iPageCurrent <> 1 Then
> %>
> <A HREF="./gnames.asp?page=<%= iPageCurrent - 1
> %>&qs2=<%= Server.URLEncode(strOrderBy)
> %>">Previous</A>
>
> <%
> ' Above spacing is inside the If so we don't get it
> unless needed
> End If
> If iPageCurrent < iPageCount Then
> %>
> <A HREF="./gnames.asp?page=<%= iPageCurrent + 1
> %>&qs2=<%= Server.URLEncode(strOrderBy) %>">Next</A>
> <% End If ' END RUNTIME CODE
> %>
>
>
>
> __________________________________________________
> Do You Yahoo!?
> Great stuff seeking new owners in Yahoo! Auctions!
> http://auctions.yahoo.com
>
$subst('Email.Unsub').
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
Message #8 by <sathish297@y...> on Fri, 25 Jan 2002 10:34:31 +0530
|
|
This is a multi-part message in MIME format.
------=_NextPart_000_00DA_01C1A58B.DFD68660
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hi Enzo,
When you have a large number of records you can't show them all at
once. So we split the records by a particular number called pagesize.
Pagesize will determine how many records to display in each page.Its
quite easy. It gets a bit fussy when there are conditions in the where
clause. Nusrat's code is a good example of paging.
1) Create a db called babynames
2) Create a table called babynames with the fields babyname, bnmean,
babycat
3) Add a few records (eg: mubashir,messenger of god, male) . Add some
with babycat 'female'
4) Create a file called gnames.asp in the directory where you have
created the db.
5) copy and paste the following code in gnames.asp
<%@ Language=3DVBScript %>
<HTML>
<HEAD>
<META NAME=3D"GENERATOR" Content=3D"Microsoft Visual Studio 6.0">
</HEAD>
<BODY>
<P> </P>
<%' BEGIN USER CONSTANTS
Dim CONN_STRING
Dim CONN_USER
Dim CONN_PASS
CONN_USER =3D ""
CONN_PASS =3D ""
CONN_STRING =3D Application("SQLConnString")
CONN_USER =3D Application("SQLUsername")
CONN_PASS =3D Application("SQLPassword")
Dim iPageSize
Dim iPageCount
Dim iPageCurrent
Dim strOrderBy
Dim strSQL
Dim objPagingConn
Dim objPagingRS
Dim iRecordsShown
Dim I
'variable to hold chosen letter A-Z from list box
if Request.Form("lttrs")<>"" then
qs2=3DRequest.Form("lttrs")
elseif Request.QueryString("qs2")<>"" then
qs2=3DRequest.QueryString("qs2")
end if
iPageSize =3D 2
If Request.QueryString("page") =3D "" Then
iPageCurrent =3D 1
Else iPageCurrent =3D CInt(Request.QueryString("page"))
End If
If Request.QueryString("qs2") =3D "" Then
strOrderBy =3D "babyid"
Else
strOrderBy =3D Request.QueryString("qs2")
End If
strSQL =3D "SELECT babyname,bnmean FROM babynames where
babycat=3D'female' and babyname like '"&qs2&"%' ORDER BY babyname asc"
'& strOrderBy & ";" "&qs2&"%
Set objPagingConn =3DServer.CreateObject("ADODB.Connection")
'objPagingConn.Open "DBQ=3D" &Server.Mappath("babynames.mdb") &
";Driver=3D{Microsoft Access Driver (*.mdb)};"
objPagingConn.Open "driver=3DMicrosoft Access Driver (*.mdb);DBQ=3D"
&Server.Mappath("babynames.mdb")
Set objPagingRS =3D Server.CreateObject("ADODB.Recordset")
objPagingRS.PageSize =3D iPageSize
objPagingRS.CacheSize =3D iPageSize
Response.Write strSql
objPagingRS.Open strSQL , objPagingConn ,3,3 '50
iPageCount =3D objPagingRS.PageCount
If iPageCurrent > iPageCount Then iPageCurrent =3DiPageCount
If iPageCurrent < 1 Then iPageCurrent =3D 1
If iPageCount =3D 0 Then
Response.Write "No records found!"
Else
objPagingRS.AbsolutePage =3D iPageCurrent
%>
<FONT SIZE=3D"+1">
Page <B>
<%=3D iPageCurrent
%>
</B> of <B>
<%=3D iPageCount
%>
</B>
</FONT>
<%
response.write qs2
' Spacing
Response.Write "<BR><BR>" & vbCrLf
' Continue with a title row in our table
Response.Write "<TABLE BORDER=3D""1"">" & vbCrLf
' Show field names in the top row
Response.Write vbTab & "<TR>" & vbCrLf
For I =3D 0 To objPagingRS.Fields.Count - 1
Response.Write vbTab & vbTab & "<TD><B>"
Response.Write objPagingRS.Fields(I).Name
Response.Write "<B></TD>" & vbCrLf
Next 'I
Response.Write vbTab & "</TR>" & vbCrLf
' Loop through our records and ouput 1 row per record
iRecordsShown =3D 0
Do While iRecordsShown < iPageSize And Not objPagingRS.EOF
Response.Write vbTab & "<TR>" & vbCrLf
For I =3D 0 To objPagingRS.Fields.Count - 1
Response.Write vbTab & vbTab & "<TD>"
Response.Write objPagingRS.Fields(I)
Response.Write "</TD>" & vbCrLf
Next 'I
Response.Write vbTab & "</TR>" & vbCrLf
' Increment the number of records we've shown
iRecordsShown =3D iRecordsShown + 1 ' Can't forget to move to the next
record!
objPagingRS.MoveNext
Loop ' All done - close table
Response.Write "</TABLE>" & vbCrLf
End If
If iPageCurrent <> 1 Then
%>
<A HREF=3D"./gnames.asp?page=3D<%=3D iPageCurrent - 1
%>&qs2=3D<%=3D Server.URLEncode(strOrderBy)
%>">Previous</A>
<%
' Above spacing is inside the If so we don't get it unless needed
End If
If iPageCurrent < iPageCount Then
%>
<A HREF=3D"./gnames.asp?page=3D<%=3D iPageCurrent + 1
%>&qs2=3D<%=3D Server.URLEncode(strOrderBy) %>">Next</A>
<% End If ' END RUNTIME CODE
%>
</BODY>
</HTML>
With Regards,
R. Sathish Kumar.
sathish297@y...
----- Original Message -----
From: Zaragoza, Enzo
To: ASP Web HowTo
Sent: Friday, January 25, 2002 1:01 AM
Subject: [asp_web_howto] RE: paging recordset
Hi guys!! Just wanna ask, where is paging recordset used?
Thanks,
Enzo :)
----- Original Message -----
From: nusrat sarwar
To: ASP Web HowTo
Sent: Friday, January 25, 2002 2:38 AM
Subject: [asp_web_howto] RE: paging recordset
Hi Sathish Kumar.
I am sending you my code (paging ASP)
see what I should do
as you said I did and it gave me required result but
when I am giving variable in querystring it is not
working please help me out
many thanx
regards
nusrat
<%' BEGIN USER CONSTANTS
Dim CONN_STRING
Dim CONN_USER
Dim CONN_PASS
CONN_USER =3D ""
CONN_PASS =3D ""
CONN_STRING =3D Application("SQLConnString")
CONN_USER =3D Application("SQLUsername")
CONN_PASS =3D Application("SQLPassword")
Dim iPageSize
Dim iPageCount
Dim iPageCurrent
Dim strOrderBy
Dim strSQL
Dim objPagingConn
Dim objPagingRS
Dim iRecordsShown
Dim I
'variable to hold chosen letter A-Z from list box
qs2=3DRequest.Form("lttrs")
iPageSize =3D 4
If Request.QueryString("page") =3D "" Then
iPageCurrent =3D 1
Else iPageCurrent =3D CInt(Request.QueryString("page"))
End If
If Request.QueryString("qs2") =3D "" Then
strOrderBy =3D "babyid"
Else
strOrderBy =3D Request.QueryString("qs2")
End If
strSQL =3D "SELECT babyname,bnmean FROM babynames where
babycat=3D'female' and babyname like '"&qs2&"%' ORDER BY
babyname asc" '& strOrderBy & ";"
"&qs2&"%
Set objPagingConn =3D
Server.CreateObject("ADODB.Connection")
objPagingConn.Open "DBQ=3D" &
Server.Mappath("babynames.mdb") & ";Driver=3D{Microsoft
Access Driver (*.mdb)};"
Set objPagingRS =3D
Server.CreateObject("ADODB.Recordset")
objPagingRS.PageSize =3D iPageSize
objPagingRS.CacheSize =3D iPageSize
objPagingRS.Open strSQL , objPagingConn ,
adOpenStatic, adLockReadOnly , adCmdText '50
iPageCount =3D objPagingRS.PageCount
If iPageCurrent > iPageCount Then iPageCurrent =3D
iPageCount
If iPageCurrent < 1 Then iPageCurrent =3D 1
If iPageCount =3D 0 Then
Response.Write "No records found!"
Else
objPagingRS.AbsolutePage =3D iPageCurrent
%>
<FONT SIZE=3D"+1">
Page <B>
<%=3D iPageCurrent
%>
</B> of <B>
<%=3D iPageCount
%>
</B>
</FONT>
<%
response.write qs2
' Spacing
Response.Write "<BR><BR>" & vbCrLf
' Continue with a title row in our table
Response.Write "<TABLE BORDER=3D""1"">" & vbCrLf
' Show field names in the top row
Response.Write vbTab & "<TR>" & vbCrLf
For I =3D 0 To objPagingRS.Fields.Count - 1
Response.Write vbTab & vbTab & "<TD><B>"
Response.Write objPagingRS.Fields(I).Name
Response.Write "<B></TD>" & vbCrLf
Next 'I
Response.Write vbTab & "</TR>" & vbCrLf
' Loop through our records and ouput 1 row per record
iRecordsShown =3D 0
Do While iRecordsShown < iPageSize And Not
objPagingRS.EOF
Response.Write vbTab & "<TR>" & vbCrLf
For I =3D 0 To objPagingRS.Fields.Count - 1
Response.Write vbTab & vbTab & "<TD>"
Response.Write objPagingRS.Fields(I)
Response.Write "</TD>" & vbCrLf
Next 'I
Response.Write vbTab & "</TR>" & vbCrLf
' Increment the number of records we've shown
iRecordsShown =3D iRecordsShown + 1 ' Can't forget to
move to the next record!
objPagingRS.MoveNext
Loop ' All done - close table
Response.Write "</TABLE>" & vbCrLf
End If
If iPageCurrent <> 1 Then
%>
<A HREF=3D"./gnames.asp?page=3D<%=3D iPageCurrent - 1
%>&qs2=3D<%=3D Server.URLEncode(strOrderBy)
%>">Previous</A>
<%
' Above spacing is inside the If so we don't get it
unless needed
End If
If iPageCurrent < iPageCount Then
%>
<A HREF=3D"./gnames.asp?page=3D<%=3D iPageCurrent + 1
%>&qs2=3D<%=3D Server.URLEncode(strOrderBy) %>">Next</A>
<% End If ' END RUNTIME CODE
%>
__________________________________________________
Do You Yahoo!?
Great stuff seeking new owners in Yahoo! Auctions!
http://auctions.yahoo.com
$subst('Email.Unsub').
$subst('Email.Unsub').
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
Message #9 by "Zaragoza, Enzo" <enzaux@g...> on Sat, 26 Jan 2002 01:31:14 +0800
|
|
This is a multi-part message in MIME format.
------=_NextPart_000_01A3_01C1A609.24E776B0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Thanks satish
----- Original Message -----
From: sathish297@y...
To: ASP Web HowTo
Sent: Friday, January 25, 2002 1:04 PM
Subject: [asp_web_howto] RE: paging recordset
Hi Enzo,
When you have a large number of records you can't show them all
at once. So we split the records by a particular number called pagesize.
Pagesize will determine how many records to display in each page.Its
quite easy. It gets a bit fussy when there are conditions in the where
clause. Nusrat's code is a good example of paging.
1) Create a db called babynames
2) Create a table called babynames with the fields babyname, bnmean,
babycat
3) Add a few records (eg: mubashir,messenger of god, male) . Add some
with babycat 'female'
4) Create a file called gnames.asp in the directory where you have
created the db.
5) copy and paste the following code in gnames.asp
<%@ Language=3DVBScript %>
<HTML>
<HEAD>
<META NAME=3D"GENERATOR" Content=3D"Microsoft Visual Studio 6.0">
</HEAD>
<BODY>
<P> </P>
<%' BEGIN USER CONSTANTS
Dim CONN_STRING
Dim CONN_USER
Dim CONN_PASS
CONN_USER =3D ""
CONN_PASS =3D ""
CONN_STRING =3D Application("SQLConnString")
CONN_USER =3D Application("SQLUsername")
CONN_PASS =3D Application("SQLPassword")
Dim iPageSize
Dim iPageCount
Dim iPageCurrent
Dim strOrderBy
Dim strSQL
Dim objPagingConn
Dim objPagingRS
Dim iRecordsShown
Dim I
'variable to hold chosen letter A-Z from list box
if Request.Form("lttrs")<>"" then
qs2=3DRequest.Form("lttrs")
elseif Request.QueryString("qs2")<>"" then
qs2=3DRequest.QueryString("qs2")
end if
iPageSize =3D 2
If Request.QueryString("page") =3D "" Then
iPageCurrent =3D 1
Else iPageCurrent =3D CInt(Request.QueryString("page"))
End If
If Request.QueryString("qs2") =3D "" Then
strOrderBy =3D "babyid"
Else
strOrderBy =3D Request.QueryString("qs2")
End If
strSQL =3D "SELECT babyname,bnmean FROM babynames where
babycat=3D'female' and babyname like '"&qs2&"%' ORDER BY babyname asc"
'& strOrderBy & ";" "&qs2&"%
Set objPagingConn =3DServer.CreateObject("ADODB.Connection")
'objPagingConn.Open "DBQ=3D" &Server.Mappath("babynames.mdb") &
";Driver=3D{Microsoft Access Driver (*.mdb)};"
objPagingConn.Open "driver=3DMicrosoft Access Driver (*.mdb);DBQ=3D"
&Server.Mappath("babynames.mdb")
Set objPagingRS =3D Server.CreateObject("ADODB.Recordset")
objPagingRS.PageSize =3D iPageSize
objPagingRS.CacheSize =3D iPageSize
Response.Write strSql
objPagingRS.Open strSQL , objPagingConn ,3,3 '50
iPageCount =3D objPagingRS.PageCount
If iPageCurrent > iPageCount Then iPageCurrent =3DiPageCount
If iPageCurrent < 1 Then iPageCurrent =3D 1
If iPageCount =3D 0 Then
Response.Write "No records found!"
Else
objPagingRS.AbsolutePage =3D iPageCurrent
%>
<FONT SIZE=3D"+1">
Page <B>
<%=3D iPageCurrent
%>
</B> of <B>
<%=3D iPageCount
%>
</B>
</FONT>
<%
response.write qs2
' Spacing
Response.Write "<BR><BR>" & vbCrLf
' Continue with a title row in our table
Response.Write "<TABLE BORDER=3D""1"">" & vbCrLf
' Show field names in the top row
Response.Write vbTab & "<TR>" & vbCrLf
For I =3D 0 To objPagingRS.Fields.Count - 1
Response.Write vbTab & vbTab & "<TD><B>"
Response.Write objPagingRS.Fields(I).Name
Response.Write "<B></TD>" & vbCrLf
Next 'I
Response.Write vbTab & "</TR>" & vbCrLf
' Loop through our records and ouput 1 row per record
iRecordsShown =3D 0
Do While iRecordsShown < iPageSize And Not objPagingRS.EOF
Response.Write vbTab & "<TR>" & vbCrLf
For I =3D 0 To objPagingRS.Fields.Count - 1
Response.Write vbTab & vbTab & "<TD>"
Response.Write objPagingRS.Fields(I)
Response.Write "</TD>" & vbCrLf
Next 'I
Response.Write vbTab & "</TR>" & vbCrLf
' Increment the number of records we've shown
iRecordsShown =3D iRecordsShown + 1 ' Can't forget to move to the next
record!
objPagingRS.MoveNext
Loop ' All done - close table
Response.Write "</TABLE>" & vbCrLf
End If
If iPageCurrent <> 1 Then
%>
<A HREF=3D"./gnames.asp?page=3D<%=3D iPageCurrent - 1
%>&qs2=3D<%=3D Server.URLEncode(strOrderBy)
%>">Previous</A>
<%
' Above spacing is inside the If so we don't get it unless needed
End If
If iPageCurrent < iPageCount Then
%>
<A HREF=3D"./gnames.asp?page=3D<%=3D iPageCurrent + 1
%>&qs2=3D<%=3D Server.URLEncode(strOrderBy) %>">Next</A>
<% End If ' END RUNTIME CODE
%>
</BODY>
</HTML>
With Regards,
R. Sathish Kumar.
sathish297@y...
----- Original Message -----
From: Zaragoza, Enzo
To: ASP Web HowTo
Sent: Friday, January 25, 2002 1:01 AM
Subject: [asp_web_howto] RE: paging recordset
Hi guys!! Just wanna ask, where is paging recordset used?
Thanks,
Enzo :)
----- Original Message -----
From: nusrat sarwar
To: ASP Web HowTo
Sent: Friday, January 25, 2002 2:38 AM
Subject: [asp_web_howto] RE: paging recordset
Hi Sathish Kumar.
I am sending you my code (paging ASP)
see what I should do
as you said I did and it gave me required result but
when I am giving variable in querystring it is not
working please help me out
many thanx
regards
nusrat
<%' BEGIN USER CONSTANTS
Dim CONN_STRING
Dim CONN_USER
Dim CONN_PASS
CONN_USER =3D ""
CONN_PASS =3D ""
CONN_STRING =3D Application("SQLConnString")
CONN_USER =3D Application("SQLUsername")
CONN_PASS =3D Application("SQLPassword")
Dim iPageSize
Dim iPageCount
Dim iPageCurrent
Dim strOrderBy
Dim strSQL
Dim objPagingConn
Dim objPagingRS
Dim iRecordsShown
Dim I
'variable to hold chosen letter A-Z from list box
qs2=3DRequest.Form("lttrs")
iPageSize =3D 4
If Request.QueryString("page") =3D "" Then
iPageCurrent =3D 1
Else iPageCurrent =3D CInt(Request.QueryString("page"))
End If
If Request.QueryString("qs2") =3D "" Then
strOrderBy =3D "babyid"
Else
strOrderBy =3D Request.QueryString("qs2")
End If
strSQL =3D "SELECT babyname,bnmean FROM babynames where
babycat=3D'female' and babyname like '"&qs2&"%' ORDER BY
babyname asc" '& strOrderBy & ";"
"&qs2&"%
Set objPagingConn =3D
Server.CreateObject("ADODB.Connection")
objPagingConn.Open "DBQ=3D" &
Server.Mappath("babynames.mdb") & ";Driver=3D{Microsoft
Access Driver (*.mdb)};"
Set objPagingRS =3D
Server.CreateObject("ADODB.Recordset")
objPagingRS.PageSize =3D iPageSize
objPagingRS.CacheSize =3D iPageSize
objPagingRS.Open strSQL , objPagingConn ,
adOpenStatic, adLockReadOnly , adCmdText '50
iPageCount =3D objPagingRS.PageCount
If iPageCurrent > iPageCount Then iPageCurrent =3D
iPageCount
If iPageCurrent < 1 Then iPageCurrent =3D 1
If iPageCount =3D 0 Then
Response.Write "No records found!"
Else
objPagingRS.AbsolutePage =3D iPageCurrent
%>
<FONT SIZE=3D"+1">
Page <B>
<%=3D iPageCurrent
%>
</B> of <B>
<%=3D iPageCount
%>
</B>
</FONT>
<%
response.write qs2
' Spacing
Response.Write "<BR><BR>" & vbCrLf
' Continue with a title row in our table
Response.Write "<TABLE BORDER=3D""1"">" & vbCrLf
' Show field names in the top row
Response.Write vbTab & "<TR>" & vbCrLf
For I =3D 0 To objPagingRS.Fields.Count - 1
Response.Write vbTab & vbTab & "<TD><B>"
Response.Write objPagingRS.Fields(I).Name
Response.Write "<B></TD>" & vbCrLf
Next 'I
Response.Write vbTab & "</TR>" & vbCrLf
' Loop through our records and ouput 1 row per record
iRecordsShown =3D 0
Do While iRecordsShown < iPageSize And Not
objPagingRS.EOF
Response.Write vbTab & "<TR>" & vbCrLf
For I =3D 0 To objPagingRS.Fields.Count - 1
Response.Write vbTab & vbTab & "<TD>"
Response.Write objPagingRS.Fields(I)
Response.Write "</TD>" & vbCrLf
Next 'I
Response.Write vbTab & "</TR>" & vbCrLf
' Increment the number of records we've shown
iRecordsShown =3D iRecordsShown + 1 ' Can't forget to
move to the next record!
objPagingRS.MoveNext
Loop ' All done - close table
Response.Write "</TABLE>" & vbCrLf
End If
If iPageCurrent <> 1 Then
%>
<A HREF=3D"./gnames.asp?page=3D<%=3D iPageCurrent - 1
%>&qs2=3D<%=3D Server.URLEncode(strOrderBy)
%>">Previous</A>
<%
' Above spacing is inside the If so we don't get it
unless needed
End If
If iPageCurrent < iPageCount Then
%>
<A HREF=3D"./gnames.asp?page=3D<%=3D iPageCurrent + 1
%>&qs2=3D<%=3D Server.URLEncode(strOrderBy) %>">Next</A>
<% End If ' END RUNTIME CODE
%>
__________________________________________________
Do You Yahoo!?
Great stuff seeking new owners in Yahoo! Auctions!
http://auctions.yahoo.com
$subst('Email.Unsub').
$subst('Email.Unsub').
$subst('Email.Unsub').
Message #10 by nusrat sarwar <nusratsarwar@y...> on Sat, 26 Jan 2002 03:18:45 -0800 (PST)
|
|
Hi satish
I tried yr solution but the problem remains the same
first 4 records are from the letter selected but on
clicking next its showing 2 page of name starting from
A not D tht was selected
so i you can help me now i'll be grateful
regards
nusrat
--- "Zaragoza, Enzo" <enzaux@g...> wrote:
> Thanks satish
>
__________________________________________________
Do You Yahoo!?
Great stuff seeking new owners in Yahoo! Auctions!
http://auctions.yahoo.com
Message #11 by <sathish297@y...> on Sun, 27 Jan 2002 21:07:29 +0530
|
|
Hi Nusrat,
Please take a look at the below code:
<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>
<P> </P>
<%' BEGIN USER CONSTANTS
Dim CONN_STRING
Dim CONN_USER
Dim CONN_PASS
CONN_USER = ""
CONN_PASS = ""
CONN_STRING = Application("SQLConnString")
CONN_USER = Application("SQLUsername")
CONN_PASS = Application("SQLPassword")
Dim iPageSize
Dim iPageCount
Dim iPageCurrent
Dim strOrderBy
Dim strSQL
Dim objPagingConn
Dim objPagingRS
Dim iRecordsShown
Dim I
'variable to hold chosen letter A-Z from list box
if Request.Form("lttrs")<>"" then
qs2=trim( Request.Form("lttrs") )
elseif Request.QueryString("qs2")<>"" then
qs2=trim ( Request.QueryString("qs2") )
end if
iPageSize = 4
If Request.QueryString("page") = "" Then
iPageCurrent = 1
Else iPageCurrent = CInt(Request.QueryString("page"))
End If
If qs2= "" Then
strOrderBy = "babyid"
Else
strOrderBy = "babyname"
End If
strSQL = "SELECT babyname,bnmean FROM babynames where babycat='female' and
babyname like '"&qs2&"%' ORDER BY "&strOrderBy&" asc "
Set objPagingConn =Server.CreateObject("ADODB.Connection")
objPagingConn.Open "DBQ=" &Server.Mappath("babynames.mdb") &
";Driver={Microsoft Access Driver (*.mdb)};"
Set objPagingRS = Server.CreateObject("ADODB.Recordset")
objPagingRS.PageSize = iPageSize
objPagingRS.CacheSize = iPageSize
Response.Write strSql
objPagingRS.Open strSQL , objPagingConn ,3,3 '50
iPageCount = objPagingRS.PageCount
If iPageCurrent > iPageCount Then iPageCurrent =iPageCount
If iPageCurrent < 1 Then iPageCurrent = 1
If iPageCount = 0 Then
Response.Write "No records found!"
Else
objPagingRS.AbsolutePage = iPageCurrent
%>
<FONT SIZE="+1">
Page <B>
<%= iPageCurrent
%>
</B> of <B>
<%= iPageCount
%>
</B>
</FONT>
<%
response.write qs2
' Spacing
Response.Write "<BR><BR>" & vbCrLf
' Continue with a title row in our table
Response.Write "<TABLE BORDER=""1"">" & vbCrLf
' Show field names in the top row
Response.Write vbTab & "<TR>" & vbCrLf
For I = 0 To objPagingRS.Fields.Count - 1
Response.Write vbTab & vbTab & "<TD><B>"
Response.Write objPagingRS.Fields(I).Name
Response.Write "<B></TD>" & vbCrLf
Next 'I
Response.Write vbTab & "</TR>" & vbCrLf
' Loop through our records and ouput 1 row per record
iRecordsShown = 0
Do While iRecordsShown < iPageSize And Not objPagingRS.EOF
Response.Write vbTab & "<TR>" & vbCrLf
For I = 0 To objPagingRS.Fields.Count - 1
Response.Write vbTab & vbTab & "<TD>"
Response.Write objPagingRS.Fields(I)
Response.Write "</TD>" & vbCrLf
Next 'I
Response.Write vbTab & "</TR>" & vbCrLf
' Increment the number of records we've shown
iRecordsShown = iRecordsShown + 1 ' Can't forget to move to the next record!
objPagingRS.MoveNext
Loop ' All done - close table
Response.Write "</TABLE>" & vbCrLf
End If
If iPageCurrent <> 1 Then
%>
<A HREF="./gnames.asp?page=<%= iPageCurrent - 1
%>&qs2=<%= Server.URLEncode(strOrderBy)
%>">Previous</A>
<%
' Above spacing is inside the If so we don't get it unless needed
End If
If iPageCurrent < iPageCount Then
%>
<A HREF="./gnames.asp?page=<%= iPageCurrent + 1
%>&qs2=<%= Server.URLEncode(strOrderBy) %>">Next</A>
<% End If ' END RUNTIME CODE
%>
</BODY>
</HTML>
Again if you get any errors pls. mail it along with the error.
With Regards,
R. Sathish Kumar,
sathish297@y...
----- Original Message -----
From: "nusrat sarwar" <nusratsarwar@y...>
To: "ASP Web HowTo" <asp_web_howto@p...>
Sent: Saturday, January 26, 2002 4:48 PM
Subject: [asp_web_howto] RE: paging recordset
> Hi satish
> I tried yr solution but the problem remains the same
> first 4 records are from the letter selected but on
> clicking next its showing 2 page of name starting from
> A not D tht was selected
> so i you can help me now i'll be grateful
> regards
> nusrat
>
> --- "Zaragoza, Enzo" <enzaux@g...> wrote:
> > Thanks satish
> >
>
> __________________________________________________
> Do You Yahoo!?
> Great stuff seeking new owners in Yahoo! Auctions!
> http://auctions.yahoo.com
>
$subst('Email.Unsub').
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
|
|
 |