?
Solved

sort table in ASP

Posted on 2009-02-12
9
Medium Priority
?
388 Views
Last Modified: 2012-05-06
I have a table that I am creating for issues. I have a field called CAC that I am using each entry in that field as a hyperlink to a form specific for that issue. My users have asked for the ability to sort this table by the headers. I have managed to get the hyperlinks attached to the headers and now each field updates, BUT...now my hyperlinks under the CAC field do not work. With the exception of the 1st entry in that column.

I believe I have made a mistake either in the placement of my form info or in the script that handles the query string. I need someone to show me where my code is wrong or incomplete.
Thanks!!
<html>
<META HTTP-EQUIV="REFRESH" CONTENT="300">
<head>
 
</head>
<body>
Export To Excel&nbsp;
<a href="Potomac_Pending_Excel.asp"><img src="images/excel.jpg" width="35" height="35" border="1" alt="Export To Excel"></a>&nbsp;&nbsp;&nbsp;Print Screen&nbsp;
<a href="javascript:window.print();"><img src="images/Print.jpg" width="35" height="35" border="1" alt="Print This Page"></a>&nbsp;&nbsp;&nbsp;Close Window&nbsp;
<a href="javascript:window.close();"><img src="images/Close.jpg" width="35" height="35" border="1" alt="Close This Window"></a>&nbsp;&nbsp;&nbsp;
 
<center>
<h1><FONT COLOR="Red">Potomac Region <br>Pending Issues (Updatable View)</FONT></h1>
<p>Select by CAC the Record to Update</p>
</center>
 
<table border="1" width="100%" bgcolor="">
<tr>
<th>Region</th>
<th>Received</th>
<th>CAC</th>
<th align="left" bgcolor="">
<a href="test_pending_update.asp?sort=CKTID">CKTID</a>
</th>
<th>ACNA</th>
<th align="left" bgcolor="">
<a href="test_pending_update.asp?sort=CUSTOMER">Customer</a>
</th>
<th align="left" bgcolor="">
<a href="test_pending_update.asp?sort=[TICKET NUMBER]">Ticket Number</a>
</th>
<th>Disposition</th>
<th>Completed</th>
<th>Summary</th>
<th align="left" bgcolor="">
<a href="test_pending_update.asp?sort=GROUP">Group</a>
</th>
</tr>
<form method="post" action="Potomac_Update_Entry.asp">
 
<%
if request.querystring("sort")<>"" then
   sort=request.querystring("sort")
else
   sort="Received DESC"
end if
%>
 
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "D:\Performance Assurance Team\Proactive.mdb"
set rs=Server.CreateObject("ADODB.Recordset")
sql="SELECT REGION,RECEIVED,CAC,CKTID,ACNA,CUSTOMER,[TICKET NUMBER],DISPOSITION,COMPLETED,SUMMARY,GROUP FROM PotomacPending ORDER BY " & sort
rs.Open sql,conn
 
do until rs.EOF
   response.write("<tr>")
   for each x in rs.Fields
     if (x.name)="CAC" then%>
    <td>
    <input type="submit" name="CAC" value="<%=x.value%>">
    </td>
  <%else%>
    <td nowrap="nowrap" ><%Response.Write(x.value)%></td>
  <%end if
next
%>
</form>
<%rs.MoveNext%>
</tr>
<%
loop
 
%>
</table><br>
 
</body>
</html>

Open in new window

0
Comment
Question by:vzdog
  • 5
  • 4
9 Comments
 
LVL 18

Expert Comment

by:Morcalavin
ID: 23625555
For one thing, you can only have one "input type="submit"" per form, which is probably why only the first one is using.

Second, you are extremely vulnerable to sql injection by allowing a querystring value to be passed into your sql statement without being sanity checked.
0
 
LVL 18

Expert Comment

by:Morcalavin
ID: 23625582
For one thing, you can only have one "input type="submit"" per form, which is probably why only the first one is using.

Actually, I may be thinking of something else here(I think I'm confusing my button elements not passing values in ie).  So ignore that statement.  My second statement still stands however.
0
 

Author Comment

by:vzdog
ID: 23625619
This is an intranet so SQL injection is not a concern.
Are you meaning the "hyper-links" are considered "submit"?
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LVL 18

Expert Comment

by:Morcalavin
ID: 23625636
you got some code out of place it seems.  try this:


do until rs.EOF
   response.write("<tr>")
   for each x in rs.Fields
     if (x.name)="CAC" then%>
    <td>
    <input type="submit" name="CAC" value="<%=x.value%>">
    </td>
  <%else%>
    <td nowrap="nowrap" ><%Response.Write(x.value)%></td>
  <%end if
next
%>
</tr>
<%rs.MoveNext%>
</form>

Open in new window

0
 

Author Comment

by:vzdog
ID: 23625638
Yes, each field in the CAC column works fine, without the addition of the sort string & links. So that is not the issue.
0
 
LVL 18

Expert Comment

by:Morcalavin
ID: 23625654
Are you meaning the "hyper-links" are considered "submit"?

Ignore my previous statements about submit.  I was thinking of button elements that have the type of submit, not input elements.
0
 

Author Comment

by:vzdog
ID: 23625764
Tried the code modification. Did not like that at all.
it set a string of vertical S's on the top of the table but nothing else
0
 
LVL 18

Accepted Solution

by:
Morcalavin earned 2000 total points
ID: 23625886
Sorry about that, they should to after and before loop.  You want to close your form after the loop, but put your closing tr for that row before the end of it.


rs.Open sql,conn
 
do until rs.EOF
   response.write("<tr>")
   for each x in rs.Fields
     if (x.name)="CAC" then%>
    <td>
    <input type="submit" name="CAC" value="<%=x.value%>">
    </td>
  <%else%>
    <td nowrap="nowrap" ><%Response.Write(x.value)%></td>
  <%end if
next
%>
<%rs.MoveNext%>
</tr>
<%
loop
%>
</form>

Open in new window

0
 

Author Closing Comment

by:vzdog
ID: 31546244
Worked great! Thanks!
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

589 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question