Can't get ASP to load a result and sort the Columns


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Can't get ASP to load a result and sort the Columns

  1. #1
    Join Date
    Apr 2005
    Posts
    1

    Can't get ASP to load a result and sort the Columns

    Would anyone be able to assist me in modifying this code so that I could get my sort request to work properly? I want to be able to select from the drop down and submit to get the results. Then I want to be able to sort each column without the page loading each time and having to select the item again.

    You can find an example of what I'm trying to do at http://www.laceymatcats.org/mcsearchform.asp

    PS. My host doesn't use ASP.NET so I'm trying to do everything through ASP.

    <html>
    <head>
    <title>Results Test</title>

    <link href="style.css" rel="stylesheet" type="text/css">
    <!-- Scroll Bar Properties -->
    <STYLE type="text/css">
    body {
    scrollbar-arrow-color: #D5D5D5;
    scrollbar-base-color: #595AA2;
    scrollbar-dark-shadow-color: #000000;
    scrollbar-track-color: #CBCBCB;
    scrollbar-face-color: #000181;
    scrollbar-shadow-color: #9E9EC5;
    scrollbar-highlight-color: #595AA2;
    scrollbar-3d-light-color: #595AA2;
    }
    </STYLE>
    </head>

    <BODY link="ffffff" alink="999999" vlink="ffffff" background="images/bkgd.gif" bgproperties="fixed">
    <% 'specify the provider
    set conn=Server.CreateObject("ADODB.Connection")
    conn.Provider="Microsoft.Jet.OLEDB.4.0"
    conn.Open(Server.Mappath("mydatabase.mdb"))

    'define the query
    sql="SELECT DISTINCT Tournament FROM tblResults ORDER BY Tournament"

    'create the recordset object
    set rs=Server.CreateObject("ADODB.recordset")
    rs.Open sql,conn

    Tournament=request.form("Tournament")
    %>

    <center>
    <form method="post">
    Choose Tournament <select name="tournament">
    <% do until rs.EOF
    response.write("<option")
    if rs.fields("Tournament")=Tournament then
    response.write(" selected")
    end if
    response.write(">")
    response.write(rs.fields("Tournament"))
    rs.MoveNext
    loop
    rs.Close
    set rs=Nothing %>
    </select>
    <input type="submit" value="Show Results">
    </form>
    </center>

    <div class="header">

    <hr size=1 width=90%>

    <%
    if Tournament<>"" then
    sql="SELECT Name,Division,Weight,Finished FROM tblResults WHERE Tournament='" & Tournament & "'"
    set rs=Server.CreateObject("ADODB.recordset")
    rs.Open sql,conn
    %>



    <div align="center">
    <table width=55% cellspacing=0 cellpadding=0 border=1>
    <col width=20%>
    <col width=15%>
    <col width=10%>
    <col width=10%>

    <!-- begin column headers -->
    <tr><% for each field in rs.Fields %>
    <th class="members"><a href="?sort=<%= field.Name %>"><%= field.Name %></th>
    <% next %></tr>
    <% 'cycle thru the record set and display each row results
    do until rs.EOF %>
    <tr><% for each field in rs.Fields %>
    <td class="results"><%= field.Value %></td>
    <% next %></tr>
    <!-- next row = next record -->
    <% 'increment record position with MoveNext method
    rs.MoveNext
    loop %>

    </table>

    <% 'close record set and flush object from memory
    rs.Close
    conn.Close
    set rs=Nothing %>
    </div>

    <br>
    <hr size=1 width=90%>
    <% end if %>
    </body>
    </html>

  2. #2
    Join Date
    May 2005
    Posts
    9
    Hi,

    on the link you need to click to sort the data, set the link to go to the page your on, but append a ?strSort=Asc or Desc depending on which way you want to sort, then do a querystring to get this from the string...e.g.

    if request.querystring("strSort") = "" then
    strSQL = "Select * FROM tblName"
    strLink = "myPage.asp?strSort=asc"
    elseif request.querystring("strSort") = "asc" then
    strSQL = "Select * FROM tblName Order By FieldName ASC"
    strLink = "myPage.asp?strSort=Desc"
    else
    strSQL = "Select * FROM tblName Order By FieldName DESC"
    strLink = "myPage.asp?strSort=asc"
    end if

    then on the linkable text....

    <a href="<%=strLink %>">sort</a>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center