We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

sort table in ASP

vzdog
vzdog asked
on
Medium Priority
400 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

Comment
Watch Question

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

Author

Commented:
This is an intranet so SQL injection is not a concern.
Are you meaning the "hyper-links" are considered "submit"?
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

Author

Commented:
Yes, each field in the CAC column works fine, without the addition of the sort string & links. So that is not the issue.
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.

Author

Commented:
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
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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Worked great! Thanks!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.