SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Non-Member
    Join Date
    Jul 2008
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ASP Sort Column Questions

    ASP Sort Column Questions



    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
    
                            %>

  2. #2
    SitePoint Addict itHighway's Avatar
    Join Date
    Jan 2008
    Location
    GUJ
    Posts
    270
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Replace paging script with following:

    Code ASP:
     
        <p id="R">
     
                <% if RecReq > 0 then %>
     
                            <a href="Student.asp?RecordNumber=<% = RecReq - RecOnPg %>&Sort=<%=Request.QueryString("Sort")%>"><span class="bold">Previous Page</a> -
     
                <% end if %>
     
                            <% if RecLast <> 1 then %>
     
                            <a href="Student.asp?RecordNumber=<% = RecReq + RecOnPg %>&Sort=<%=Request.QueryString("Sort")%>"><span class="bold">Next Page</span></a><% else %>Next<% end if %>
     
                </p>

  3. #3
    Non-Member
    Join Date
    Jul 2008
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried but it still does not work. When I clicked to sort Start, and Clicked on the Next Page, it goes back to sort Name by Ascending, but not Start column.

    Thanks.

  4. #4
    Non-Member
    Join Date
    Jul 2008
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When I tried to enter manually with this link on the address box, it worked
    <a href="Student.asp?RecordNumber=<% = RecReq + RecOnPg %>&ID=&sby=Start&Start=&Sort=<%=Request.QueryString("Sort")%>"><span class="bold">Next Page</span></a><% else %>Next<% end if %>

    How do I do dynamically so that it works on Name and End columns?

    This part is what I needed: &ID=&sby=Start&Start=&

    Thanks.

  5. #5
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,290
    Mentioned
    122 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by itHighway View Post
    Replace paging script with following:
    Close - the sort by fields is not included there....

    Code ASP:
    <p id="R">
    <% if RecReq > 0 then %>
    <a href="Student.asp?RecordNumber=<% = RecReq - RecOnPg %>&sby=<%=Request.QueryString("sby")%>&Sort=<%=Request.QueryString("Sort")%>"><span class="bold">Previous Page</a> -
    <% end if %>
    <% if RecLast <> 1 then %>
    <a href="Student.asp?RecordNumber=<% = RecReq + RecOnPg %>&sby=<%=Request.QueryString("sby")%>&Sort=<%=Request.QueryString("Sort")%>"><span class="bold">Next Page</span></a><% else %>Next<% end if %>
    </p>
    [/QUOTE]
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style
    Learn how to be ready for The Forums' Move to Discourse

  6. #6
    Non-Member
    Join Date
    Jul 2008
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It works perfect.

    Thank you very much.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •