troubleshooting Question

Changing order of records in ASP (Dynamically?)

Avatar of djfenom
djfenom asked on
ASP
6 Comments1 Solution377 ViewsLast Modified:
I've got this page, http://www.arrivalpreview.co.uk/testing/temp.asp, which allows me to change the order of records in a database, you can move them up or down and then the order is calculated in the database. It works well, but the list of records is likely to get pretty big, so if the order needed changing at the bottom up a few places, it could take a while for the page to load, then move down to the bottom of the page and move the record up again. I was wondering if there would be any dynamic way of doing this so the page didn't need to keep re-loading, or some sort of ajax script to drag a record to whatever position you wanted it?

Please feel free to experiment on my preview page.

My current code is as follows:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include virtual="/testing/Connections/seasiders.asp" -->
<%
if request.Form("update") = "yes" then
  set adoCn = Server.CreateObject("ADODB.Connection")
  adoCn.Open MM_cmroach_STRING
  arrRecs = split(request.Form("recordlist"),",")
  for i = lbound(arrRecs) to ubound(arrRecs)
    SQL = "Update products set prodOrder = " & request.Form("product" & arrRecs(i)) & " where prodID = " & arrRecs(i) &  ""
    set RS = adoCn.execute(SQL)
    'response.write SQL & "<br>"
  next
  SQL = ""
  adoCn.Close
  set adoCn = Nothing
end if

Set RS = Server.CreateObject("ADODB.Recordset")
RS.ActiveConnection = MM_cmroach_STRING
RS.Source = "SELECT * FROM products WHERE prodCategory = 47 ORDER BY prodOrder ASC"
RS.Open()
arrProds = RS.getrows()
RS.Close()
Set RS = Nothing
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Crown Office Chambers</title>

<link href="../style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
      function upOne(i,j)
            {
            el                  =      document.form1.elements['product'+i]
            el.value      =      el.value-1
            el                  =      document.form1.elements['product'+j]
            el.value      =      el.value-1+2
            //alert(el);
            document.form1.submit()
            }
      function downOne(i,j)
            {
            el                  =      document.form1.elements['product'+i]
            el.value      =      el.value-1+2
            el                  =      document.form1.elements['product'+j]
            el.value      =      el.value-1
            //alert(el);
            document.form1.submit()
            }
</script>

</head>

<body id="maintenance">
<form name="form1" method="post" action="">
<div id="holder">
  <div id="header"><img src="../images/logo.gif" width="274" height="20" /></div>
  <div id="content">
    <div id="left">
      <h1>Amend/Delete Member </h1>
      <table width="558" border="0" cellspacing="0" cellpadding="2">
        <tr>
          <td style="border-bottom:1px solid gainsboro;">&nbsp;</td>
          <td style="border-bottom:1px solid gainsboro;">&nbsp;</td>
          <td style="border-bottom:1px solid gainsboro;" width="322"><b>Member Name </b></td>
          </tr>
        <%
            for i = lbound(arrProds,2) to ubound(arrProds,2)
            reclist = reclist & arrProds(0,i) & ","
            %>
        <tr>
          <td style="border-bottom:1px solid gainsboro;">
              <% if i <> lbound(arrProds,2) then %>
                  <img style="cursor:pointer; " src="moveup.gif" onclick="upOne('<%=arrProds(0,i)%>','<%=arrProds(0,i-1)%>');" alt="move up">&nbsp;
              <% else %>
                  <img src="spacer.gif">&nbsp;
              <% end if %>              </td>
          <td style="border-bottom:1px solid gainsboro;">
              <% if i <> ubound(arrProds,2) then %>
                  <img style="cursor:pointer; " src="movedown.gif" onclick="downOne('<%=arrProds(0,i)%>','<%=arrProds(0,i+1)%>');" alt="move down">&nbsp;
              <% else %>
                  <img src="spacer.gif">&nbsp;
              <% end if %>              </td>
          <td style="border-bottom:1px solid gainsboro;"><%=arrProds(1,i)%><input type="hidden" id="member<%=arrProds(0,i)%>" name="product<%=arrProds(0,i)%>" value="<%=i%>"></td>
          </tr>
        <%next%>
       </table>
      <p><b>&laquo;</b> <a href="access.html">Back to main menu</a></p>
    </div>
  </div>
</div>
<input type="hidden" id="recordlist" name="recordlist" value="<%=left(reclist,len(reclist)-1)%>">
<input type="hidden" id="update" name="update" value="yes">
</form>
</body>
</html>

Many thanks

Chris
ASKER CERTIFIED SOLUTION
djfenom

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros