Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying record selected from dynamic list

Status
Not open for further replies.

Fazee

Technical User
Feb 12, 2004
10
GB
I am very new to Ultradev ASP and VB and am struggling to perform the simplest task (well seems simple in theory).
I have a list box which is displaying dynamiv data from my access database but when the user selects an item (room) from the list I would like to display the record for that particular selection on the same page.

It's doing my head in, please someone shed some light, preferably by using the server behaviours, data bindings etc rather than hard code.

Many thanks in advance.

From a confused user.
 
Create a recordset that pulls out the room deatils based on a passed url variable. Then bind the details into a table for display. Highlight the relevant rows of the table and select the Show/Hide behaviour and only show if the recordset is not empty. Now have your dropdown (values to include the variable you are using for the recordset) and form to point at the same page it is on.

This will allow users to first visit the page. As no selection has been made the recordset will be empty and nothing will be displayed, no errors generated also. When they make a selection the page will reload and display the data they wish to see.

Cheech

[Peace][Pipe]
 
when i create a variable giving it the runtime value of that in the drop down list, i get this error:

Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC Microsoft Access Driver] Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'.

I have created 2 recordsets one is used to populate the list with names of rooms and the other is used to display the corressponding data selected from the list.
 
The first recordset just pulls names and ref. The second will pull details from the URL. Post the page code.

Cheech

[Peace][Pipe]
 
ok here goes - it may be a bit of a mess because i've been messing about with it trying different things to get it to work:

<%@LANGUAGE=&quot;VBSCRIPT&quot;%>
<!--#include file=&quot;Connections/localBookingDatabase.asp&quot; -->
<%
Dim rstest__MMColParam
rstest__MMColParam = &quot;Room&quot;
if (Request(&quot;MM_EmptyValue&quot;) <> &quot;&quot;) then rstest__MMColParam = Request(&quot;MM_EmptyValue&quot;)
%>
<%
set rstest = Server.CreateObject(&quot;ADODB.Recordset&quot;)
rstest.ActiveConnection = MM_localBookingDatabase_STRING
rstest.Source = &quot;SELECT * FROM Resource WHERE Description = '&quot; + Replace(rstest__MMColParam, &quot;'&quot;, &quot;''&quot;) + &quot;'&quot;
rstest.CursorType = 0
rstest.CursorLocation = 2
rstest.LockType = 3
rstest.Open()
rstest_numRows = 0
%>
<%
Dim rsdisplay__select
rsdisplay__select = &quot;Chatsworth&quot;
if (Request.Form(&quot;select&quot;) <> &quot;&quot;) then rsdisplay__select = Request.Form(&quot;select&quot;)
%>
<%
set rsdisplay = Server.CreateObject(&quot;ADODB.Recordset&quot;)
rsdisplay.ActiveConnection = MM_localBookingDatabase_STRING
rsdisplay.Source = &quot;&quot; + Replace(rsdisplay__select, &quot;'&quot;, &quot;''&quot;) + &quot; ResourceID, Description, IdentifyingInformation, CostPerHalfDay FROM Resource WHERE IdentifyingInformation = '&quot; + Replace(rsdisplay__select, &quot;'&quot;, &quot;''&quot;) + &quot;'&quot;
rsdisplay.CursorType = 0
rsdisplay.CursorLocation = 2
rsdisplay.LockType = 3
rsdisplay.Open()
rsdisplay_numRows = 0
%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
</head>
<body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot;>
<p> </p>
<form name=&quot;form3&quot; method=&quot;post&quot; action=&quot;lynnestest.asp&quot;>
<table width=&quot;75%&quot; border=&quot;1&quot;>
<tr>
<td>
<select name=&quot;select&quot;>
<%
While (NOT rstest.EOF)
%>
<option value=&quot;<%=(rstest.Fields.Item(&quot;ResourceID&quot;).Value)%>&quot; ><%=(rstest.Fields.Item(&quot;IdentifyingInformation&quot;).Value)%></option>
<%
rstest.MoveNext()
Wend
If (rstest.CursorType > 0) Then
rstest.MoveFirst
Else
rstest.Requery
End If
%>
</select>
</td>
<td><%= FormatCurrency((rsdisplay.Fields.Item(&quot;CostPerHalfDay&quot;).Value), -1, -2, -2, -2) %></td>
</tr>
</table>
</form>
<p> </p>
<form name=&quot;form1&quot; method=&quot;post&quot; action=&quot;&quot;>
</form>
<p> </p>
<p> </p>
</body>
</html>
<%
rstest.Close()
%>
<%
rsdisplay.Close()
%>


Thank you for taking time out to help.
 
This recordset needs a SELECT
Code:
<%
set rsdisplay = Server.CreateObject(&quot;ADODB.Recordset&quot;)
rsdisplay.ActiveConnection = MM_localBookingDatabase_STRING
rsdisplay.Source =
SELECT
Code:
&quot;&quot; + Replace(rsdisplay__select, &quot;'&quot;, &quot;''&quot;) + &quot; ResourceID, Description, IdentifyingInformation, CostPerHalfDay  FROM Resource  WHERE IdentifyingInformation = '&quot; + Replace(rsdisplay__select, &quot;'&quot;, &quot;''&quot;) + &quot;'&quot;
rsdisplay.CursorType = 0
rsdisplay.CursorLocation = 2
rsdisplay.LockType = 3
rsdisplay.Open()
rsdisplay_numRows = 0
%>

Cheech

[Peace][Pipe]
 
This doesn't work Cheech
code looks like this now:


<%@LANGUAGE=&quot;VBSCRIPT&quot;%>
<!--#include file=&quot;Connections/localBookingDatabase.asp&quot; -->
<%
Dim rstest__MMColParam
rstest__MMColParam = &quot;Room&quot;
if (Request(&quot;MM_EmptyValue&quot;) <> &quot;&quot;) then rstest__MMColParam = Request(&quot;MM_EmptyValue&quot;)
%>
<%
set rstest = Server.CreateObject(&quot;ADODB.Recordset&quot;)
rstest.ActiveConnection = MM_localBookingDatabase_STRING
rstest.Source = &quot;SELECT * FROM Resource WHERE Description = '&quot; + Replace(rstest__MMColParam, &quot;'&quot;, &quot;''&quot;) + &quot;'&quot;
rstest.CursorType = 0
rstest.CursorLocation = 2
rstest.LockType = 3
rstest.Open()
rstest_numRows = 0
%>
<%
Dim rsdisplay__display
rsdisplay__display = &quot;4&quot;
if (Request.Form(&quot;select&quot;) <> &quot;&quot;) then rsdisplay__display = Request.Form(&quot;select&quot;)
%>
<%
set rsdisplay = Server.CreateObject(&quot;ADODB.Recordset&quot;)
rsdisplay.ActiveConnection = MM_localBookingDatabase_STRING
rsdisplay.Source = &quot;SELECT ResourceID, Description, IdentifyingInformation, CostPerHalfDay FROM Resource WHERE ResourceID = &quot; + Replace(rsdisplay__display, &quot;'&quot;, &quot;''&quot;) + &quot;&quot;
rsdisplay.CursorType = 0
rsdisplay.CursorLocation = 2
rsdisplay.LockType = 3
rsdisplay.Open()
rsdisplay_numRows = 0
%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
</head>
<body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot;>
<p> </p>
<form name=&quot;form3&quot; method=&quot;post&quot; action=&quot;tektips.asp&quot;>
<table width=&quot;75%&quot; border=&quot;1&quot;>
<tr>
<td>
<select name=&quot;select&quot;>
<%
While (NOT rstest.EOF)
%>
<option value=&quot;<%=(rstest.Fields.Item(&quot;ResourceID&quot;).Value)%>&quot; <%if (CStr(rstest.Fields.Item(&quot;ResourceID&quot;).Value) = CStr(rsdisplay.Fields.Item(&quot;IdentifyingInformation&quot;).Value)) then Response.Write(&quot;SELECTED&quot;) : Response.Write(&quot;&quot;)%>><%=(rstest.Fields.Item(&quot;IdentifyingInformation&quot;).Value)%></option>
<%
rstest.MoveNext()
Wend
If (rstest.CursorType > 0) Then
rstest.MoveFirst
Else
rstest.Requery
End If
%>
</select>
</td>
<td><%= FormatCurrency((rsdisplay.Fields.Item(&quot;CostPerHalfDay&quot;).Value), -1, -2, -2, -2) %></td>
</tr>
</table>
</form>
<p> </p>
<form name=&quot;form1&quot; method=&quot;post&quot; action=&quot;&quot;>
</form>
<p> </p>
<p> </p>
</body>
</html>
<%
rstest.Close()
%>
<%
rsdisplay.Close()
%>


<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
</head>

<body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot;>

</body>
</html>
 
IT WORKS

the problem was that there was no action for it to submit the request! i added an onchange behaviour which works instead of pressing a button but now i have another problem.

I have one page but need about 4/5 DD boxes on the same page (because this will finally be a booking form) but when i make a selection, because the form submits to itself, it refreshes the page hence loses that selection that the user made from the previous list. I need it to retain all the selections but do IF this can be because the page submitting to itself so I can understand why it loses the data.

I know you have posted an answer to this question on Tek-Tips but the coding goes over my head!

Thanks Cheech!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top