Forum Moderators: open

Message Too Old, No Replies

Problem with Listbox filled with values of a second table!

         

stud3

1:10 pm on Feb 18, 2005 (gmt 0)

10+ Year Member



Hi,
With the following Code I intend to show values to update, the inputs in the formular have to be already filled with values from the database. I have troubles trying to solve the problem. I think, the problem is the Listbox. I work with two tables. The table LU_Product(columns:Product_id, Product, Service_ID, Report) takes the values of the column Service in the table LU_Service (colummns: Service_ID, Service)to fill the Listbox. I wanted to do this with a Loop. I tried with While.. but it didn't work, so I tried with For...To...Next, it worked, but not completelly, the inputs are filled with the values of the database, but the listbox shows me 29x (For 1 To 29) the same Service value. Does anybody have an Idea, how can I solve the problem? ... regards.

PD: The Listbox must show the selected value and the user should have the possibility to select another value in the Listbox.

<body bgcolor="#ffffea">
<form action="change.asp" method="post">
<input type="hidden" id="form_action" name="form_action" value="chg_save">
<input type="hidden" id="Product_id" name="Product_id" value="<%Response.write(Request("Product_id")) %>">
<div>
<table align=center cellspacing=1 cellpadding=0 width="100%" border=0>
<tr><td height=25 class="headback"><font size=2><b>LU_PRODUCT - SAVE CHANGES</b></font></td></tr>
<tr><td height=15 class="textback" valign=middle style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:13px">You can change the following records:
</td>
</tr>
</table>
</div><br><br>
<div>
<table border=0 width=100% align="center" height="200">
<tr><td class="text"><b>Product:</b></td></tr>
<tr><td class="text"><input type="text" name="Product" size="40" maxlength="50" value="<%Response.write objRS("Product") %>"></td></tr>
<tr><td class="text" ><b>Service:</b></td></tr>
<tr><td class="text">
<select id="Service" name="Service" style="width:180px;">
<%
Dim SQLquery, objRS, strConn
strConn = ".."
SQLquery="SELECT p.*, s.Service FROM LU_Product AS p LEFT OUTER JOIN LU_Service AS s on s.Service_ID=p.Service_ID WHERE Product_id=" & Request("Product_id")

Set objRS = Conn.Execute(SQLquery)
While not objRS.EOF
Response.Write("<option value=" & Service_ID)
'If Service_ID = objRS("Service_ID") Then Response.Write("SELECTED")

Response.Write(">")
Response.Write objRS("Service")
Response.Write ("</option>")
objRS.MoveNext
Wend

%>

</select>
</td></tr>
<tr><td class="text" colspan=2> <b>Report:</b></td></tr>
<tr><td colspan=2><input type="text" name="Report" value="<% Response.write objRS("Report") %>" size="40" maxlength="50"></td></tr>
</table>
...

mattglet

1:52 pm on Feb 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you getting an error, or just incorrect output?

If you can provide either the error or your output, that would be most helpful.

stud3

2:38 pm on Feb 18, 2005 (gmt 0)

10+ Year Member



Thanks for answering, I am getting an error like this:
(trnslated from german)
ADODB.Field Fehler "80020009'

Either BOF or EOF is True, or the current row was deleted. The request process needs a current row.

/_rootverzeichnis/change.asp, line 0

The list box shows me the corresponding value to the selected row, but the user can't select any other value in the Listbox, if he wants to update the Service value (Is it clear?).
The Report input shows me nothing. It doesn't show me the Report value corresponding to the selected row. I think the error is in the listbox...

Jimmy Turnip

5:01 pm on Feb 18, 2005 (gmt 0)

10+ Year Member



In your sql statement you are only selecting one record set, so when you move to the next record set it is already at the end by the time you come to render the input box.

stud3

5:59 pm on Feb 18, 2005 (gmt 0)

10+ Year Member



Hi Jimmy,
thanks for answering, you are right, that's what I was thinking of, but what can I do, when I use the following Code:

<% if objRS("Service_ID")=0 then %>
<option value="0" selected>Old contracts</option>
<%else%>
<option value="0">Old contracts</option>
<%end if%>

<% if objRS("Service_ID")=1 then %>
<option value="1" selected>Application Services</option>
<%else%>
<option value="1">Application Services</option>
<%end if%>
...
and so on, it works, the value corresponding to the selected row on the table, is shown in the Listbox, and the User can select another value in the Listbox too. But the problem: I use hier one table and I fill the large Code with "If"s (example above) 29x. How can I do this with two tables?, I tried so:

For Each Product_id in objRS.Fields
if Service_ID= objRS("Service_ID") then
Response.Write "<OPTION VALUE = " & objRS("Service_ID") & "SELECTED>"
Response.Write objRS("Service") & "</Option>"
else
Response.Write "<OPTION VALUE = " & objRS("Dienstleistungs_ID") & ">"
Response.Write objRS("Dienstleistung") & "</Option>"
End If
Next

It shows me the correct outputs, but I can't select another value in the Listbox, I can see only one value. I work here with 2 Tables, what I explained in my first question.

I would be happy, if that finally worked! I have so much stress.

carguy84

4:46 am on Feb 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



hey "stud"

first:
<%Response.write(Request("Product_id")) %>
you should write as:
<%=Request("Product_id")%>
it's the same thing.

as for the loop:
<select name=serviceId>
<%
if not objRS.EOF and not objRS.BOF then
while not objRS.EOF
%>
<option value="<%=objRS("Service_ID")%>" <% if Service_Id = objRS("Service_ID") then Response.Write(" SELECTED") end if%>><%=objRS("Service")%>
<%
objRS.MoveNext
wend
end if
%>
</select>

I'm not sure what you need with the second table, but this should get you going.

Chip-

stud3

11:38 am on Feb 19, 2005 (gmt 0)

10+ Year Member



thanks carguy for answering, I will try with your lines. With the second table LU_Service I can fill the Listbox, because it has the column Service, the values there fill the listbox. You can read once again my first question in this topic, I described it there. Regards.

stud3

5:13 pm on Feb 19, 2005 (gmt 0)

10+ Year Member



hi carguy, it didn`t work , I have the Error:
ADODB.Field Fehler "80020009'

Either BOF or EOF is True, or the current row was deleted. The request process needs a current row.

I can't believe, this problem is difficult to solve, I've been searching for a topic like this in Internet, but I didn't find anything...

Table LU_Product
-----------------
Product_id
Service_ID
Product
Report

Table LU_Service
-----------------
Service_ID
Service

stud3

10:12 pm on Mar 4, 2005 (gmt 0)

10+ Year Member



I must write a correction of my mistake, I use a combobox, and not a listbox, I hope I have answers soon.