Feather Member
Posts : 27 Join date : 2011-03-09
| Subject: ASP Sort Column Questions Mon Apr 18, 2011 10:17 pm | |
| Hello, I used ASP code to sort by Column in a Table as the code below. It worked successfully by the first field (Name). When I sort by Start or End date, it works. However, when I click on Next Page, the sort goes back to Name by ASC, instead of continuing from the Start date. Here is what I need to do. When I click on Start column to sort, the Next Page should sort by Start column. When I click on End column to sort, the Next Page should sort by End column. Can anyone tell me what I need to change to make it work? Thanks very much. - Code:
-
<% Sort = Request.QueryString("Sort")
sby = Request.QueryString("sby")
SELECT CASE Sort
CASE "asc"
Sort = "desc"
CASE "desc"
Sort = "asc"
CASE "else"
Sort = "asc"
END SELECT
Set myConn = Server.CreateObject("ADODB.Connection")
myConn.open strConn
dim RecOnPg, RecReq, RecordNumber, AllRec, RecHid, RecShow, RecLast, RecCou, PgList, PgListCou
RecOnPg = 30
AllRec = 0
strSQL = "Select * From tbl_Student "
if len(sby) > 0 then _
strSQL = strSQL & " order by " & sby & " " & Sort
Set oRs = Server.CreateObject("adodb.RecordSet")
oRs.Open strSQL, myConn
do until oRs.EOF
AllRec = AllRec + 1
oRs.movenext
loop
RecordNumber = request.querystring("RecordNumber")
if RecordNumber = 0 OR RecordNumber = "" then
RecReq = 0
else
RecReq = RecReq + RecordNumber
end if
strSQL = "Select * From tbl_Student "
if len(sby) > 0 then _
strSQL = strSQL & " order by " & sby & " " & Sort
Set oRs = Server.CreateObject("adodb.RecordSet")
oRs.Open strSQL, myConn
RecHid = RecReq
do until RecHid = 0 OR oRs.EOF
RecHid = RecHid - 1
oRs.movenext
if oRs.EOF then
RecLast = 1
end if
loop
%>
<html>
<head><title>Hello world</title></head>
<body>
<table width="960" align="center">
<tr>
<td>
<table>
<tr height="25">
<td> <a href="Student.asp?ID=<%=Request("ID")%>&sby=Name&Name=<%=Post%>&Sort=<%=Sort%>">Name</a></td>
<td> <a href="Student.asp?ID=<%=Request("ID")%>&sby=Start&Start=<%=Start%>&Sort=<%=Sort%>">Start</a></td>
<td> <a href="Student.asp?ID=<%=Request("ID")%>&sby=End&End=<%=End%>&Sort=<%=Sort%>">End</a></td>
</tr>
<%
RecShow = RecOnPg
RecCou = RecReq
do until RecShow = 0 OR oRs.EOF
RecCou = RecCou + 1
%>
<tr>
<td><%=oRs("Name")%></a></td>
<td <%=sRowStyle%>><%=oRs("Start")%></td>
<td <%=sRowStyle%>><%=oRs("End")%></td>
</tr>
<%
RecShow = RecShow - 1
oRs.movenext
if oRs.EOF then
RecLast = 1
end if
loop
%>
</table>
<%
PgList = 0
PgListCou = 0
do until PgList > AllRec
PgListCou = PgListCou + 1
%>
<%
PgList = PgList + RecOnPg
loop
%>
<p id="R">
<% if RecReq > 0 then %>
<a href="Student.asp?RecordNumber=<% = RecReq - RecOnPg %>"><span class="bold">Previous Page</a> -
<% end if %>
<% if RecLast <> 1 then %>
<a href="Student.asp?RecordNumber=<% = RecReq + RecOnPg %>"><span class="bold">Next Page</span></a><% else %>Next<% end if %>
</p>
<%
oRs.close
myConn.close
%>
|
|
Carbon Member
Posts : 12 Join date : 2011-03-09
| Subject: Re: ASP Sort Column Questions Mon Apr 18, 2011 10:18 pm | |
| Look at your code: - Code:
-
<a href="Student.asp?ID=<%=Request("ID")%>&sby=Name&Name=<%=Post%>&Sort=<%=Sort%>">Name</a> <a href="Student.asp?ID=<%=Request("ID")%>&sby=Start&Start=<%=Start%>&Sort=<%=Sort%>">Start</a> <a href="Student.asp?ID=<%=Request("ID")%>&sby=End&End=<%=End%>&Sort=<%=Sort%>">End</a>
Now compare those to these: - Code:
-
<a href="Student.asp?RecordNumber=<% = RecReq - RecOnPg %>"> <a href="Student.asp?RecordNumber=<% = RecReq + RecOnPg %>">
FInally, look at your code that figures out what to sort by: - Code:
-
Sort = Request.QueryString("Sort") sby = Request.QueryString("sby")
Tell us: Where is your ASP code supposed to get the value of Request.QueryString("Sort") from when the user clicks on either of those paging links? You must put in the Sort and Sby parameters for *THOSE* links, as well. |
|
Feather Member
Posts : 27 Join date : 2011-03-09
| Subject: Re: ASP Sort Column Questions Mon Apr 18, 2011 10:19 pm | |
| Sby tells what column(s) to sort. Sort tells whether it sorts by ASC or DESC.
Thanks. |
|
Carbon Member
Posts : 12 Join date : 2011-03-09
| Subject: Re: ASP Sort Column Questions Mon Apr 18, 2011 10:19 pm | |
| |
|
Sponsored content
| Subject: Re: ASP Sort Column Questions | |
| |
|