by David Koopman / Keith Stewart, Jason Donovan (1 Submission)
Category: Miscellaneous
Compatability: VB Script
Difficulty: Unknown Difficulty
Originally Published: Sat 12th May 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Using ASP, Javascript, and SQL Server return records and then by clicking an arrow, sort records either Ascending or Descending using Stored
<%
'Establish Connection
Set oConn = server.CreateObject("ADODB.Connection")
oConn.Open "driver={SQL Server};Server=YourServer;DATABASE" & _
"=YourDatabase;UID=UserID"
'Check to see if page just loaded or Sort arrow was selected.
'Hidden text box used to test for this. As page is loaded the value
'equals "". Once the page is finished loading it will equal "Loading".
If Request.Form("text1") = "" Then
Set oCMD = server.CreateObject("ADODB.Command")
Set oCMD.ActiveConnection = oConn
oCMD.CommandType = 4
'This stored procedure returns records unsorted
oCMD.CommandText = "sp_NonReceipt"
Set oRS = server.CreateObject("ADODB.Recordset")
Set oRS = oCMD.Execute
oRS.MoveFirst
'Check to see which sort arrow was clicked by the QueryString passed
'on the Form Submission
ElseIf Request.QueryString = "sortFundASC" Then
Set oCMD = server.CreateObject("ADODB.Command")
Set oCMD.ActiveConnection = oConn
oCMD.CommandType = 4
'Return records sorted Ascending
oCMD.CommandText = "sp_NRorderFundASC"
Set oRS = server.CreateObject("ADODB.Recordset")
Set oRS = oCMD.Execute
oRS.MoveFirst
Else
Set oCMD = server.CreateObject("ADODB.Command")
Set oCMD.ActiveConnection = oConn
oCMD.CommandType = 4
'Return records sorted Descending
oCMD.CommandText = "sp_NRorderFundDSC"
Set oRS = server.CreateObject("ADODB.Recordset")
Set oRS = oCMD.Execute
oRS.MoveFirst
End If
%>
<html>
<head>
<Script language="JavaScript">
function fundASC()
{
var qString
//Set Querystring = ID of selected Arrow
qString = document.getElementById("sortFundAsc").id;
document.frmNCR.action = "Credit.asp?"+qString;
document.frmNCR.submit()
}
function fundDSC()
{
var qString
qString = document.getElementById("sortFundDsc").id;
document.frmNCR.action = "Credit.asp?"+qString;
document.frmNCR.submit()
}
</Script>
<meta NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</head>
<body>
<center>
<form action="Credit.asp" id="frmNCR" name="frmNCR" method=post>
<br>
<img src="images/uparrow_yellow.gif" WIDTH="15" HEIGHT="11" name="sortFundASC" id="sortFundASC" onClick="fundASC()">
<img src="images/downarrow_yellow.gif" WIDTH="15" HEIGHT="11" name="sortFundDsc" id="sortFundDsc" onClick="fundDSC()">
<table border="1" bgcolor="Silver">
<th><font color="Navy" face="Verdana" size="2">No. Recs</font></th>
<th><font color="Navy" face="Verdana" size="2">Bank Code</font></th>
<th><font color="Navy" face="Verdana" size="2">Cust ID</font></th>
<th><font color="Navy" face="Verdana" size="2">009</font></th>
<th><font color="Navy" face="Verdana" size="2">011</font></th>
<%'Display returned records
'i is only to determine number of records. Can be removed
i = 1
Do Until oRS.EOF
Response.Write "<TR><TD align=center><FONT color=Navy face=Arial size=2>" & i & "</TD>"
Response.Write "<TD align=center><FONT color=Navy face=Arial size=2>" & ors.Fields.Item("bankcode").Value & "</TD>"
Response.Write "<TD><FONT color=Navy face=Arial size=2>" & oRS.Fields.Item("custid").Value & "</TD>"
Response.Write "<TD><FONT color=Navy face=Arial size=2>" & oRS.Fields.Item("col009").Value & "</TD>"
Response.Write "<TD><FONT color=Navy face=Arial size=2>" & oRS.Fields.Item("col011").Value & "</TD></TR>"
oRS.MoveNext
i = i + 1
Loop
%>
</table>
<br>
<input type="hidden" id="text1" name="text1" value="Loading">
<%
'Kill objects to release from memory.
oConn.Close
set oRS = nothing
set oCMD = nothing
set oConn = nothing
%>
</form>
</body>
</html>
No comments have been posted about Using ASP, Javascript, and SQL Server return records and then by clicking an arrow, sort records ei. Why not be the first to post a comment about Using ASP, Javascript, and SQL Server return records and then by clicking an arrow, sort records ei.