Easy A
Would you like to react to this message? Create an account in a few clicks or log in to continue.


 
HomeHome  Latest imagesLatest images  SearchSearch  RegisterRegister  Log inLog in  

Share
 

 ASP Sort Column Questions

View previous topic View next topic Go down 
AuthorMessage
Feather
Member
Member
avatar

Posts : 27
Join date : 2011-03-09

ASP Sort Column Questions Empty
PostSubject: ASP Sort Column Questions   ASP Sort Column Questions EmptyMon 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>&nbsp;<a href="Student.asp?ID=<%=Request("ID")%>&sby=Name&Name=<%=Post%>&Sort=<%=Sort%>">Name</a></td>

                                                            <td>&nbsp;<a href="Student.asp?ID=<%=Request("ID")%>&sby=Start&Start=<%=Start%>&Sort=<%=Sort%>">Start</a></td>

                                                            <td>&nbsp;<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

                        %>
Back to top Go down
Carbon
Member
Member
avatar

Posts : 12
Join date : 2011-03-09

ASP Sort Column Questions Empty
PostSubject: Re: ASP Sort Column Questions   ASP Sort Column Questions EmptyMon 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.
Back to top Go down
Feather
Member
Member
avatar

Posts : 27
Join date : 2011-03-09

ASP Sort Column Questions Empty
PostSubject: Re: ASP Sort Column Questions   ASP Sort Column Questions EmptyMon Apr 18, 2011 10:19 pm

Sby tells what column(s) to sort. Sort tells whether it sorts by ASC or DESC.

Thanks.
Back to top Go down
Carbon
Member
Member
avatar

Posts : 12
Join date : 2011-03-09

ASP Sort Column Questions Empty
PostSubject: Re: ASP Sort Column Questions   ASP Sort Column Questions EmptyMon Apr 18, 2011 10:19 pm

i know what haha
Back to top Go down
Sponsored content




ASP Sort Column Questions Empty
PostSubject: Re: ASP Sort Column Questions   ASP Sort Column Questions Empty

Back to top Go down
 

ASP Sort Column Questions

View previous topic View next topic Back to top 
Page 1 of 1

 Similar topics

-
» Add a custom string property to a linklabel?Dear all I am totally new to visual C#. Whilst I can sort of manage console apps, I easily get lost when it comes to coding forms. I am currently making an "app launcher" which reads a text file line by line.

Permissions in this forum:You cannot reply to topics in this forum
Easy A :: ASP Sort Column Questions Edit-trash Useless :: Trash-