Click to See Complete Forum and Search --> : session for list/menu problem


azrina
04-28-2006, 12:35 AM
Hi all.
I use list/menu in my web application.
I am having problem for the list/menu to hold the value entered by user if there are alert message displayed after clicking submit button.
The page will be refreshed and I want the same data to be hold there.
So, I have used session() to store the data. But, the problem is it works only with textfield not for the list/menu. Only textfield in the page can store the data. May be, I didnt know the correct code for that.

Here, I enclose my code for the list menu and hope that anyone here can help me correct the code. Thanks in advance.


<select name ="negeri" class="text_normal" id="negeri">
<%
set gnegeri = server.CreateObject("adodb.recordset")
gnegeri.open "select * from negeri" ,conn
if not gnegeri.eof then
for y=1 to gnegeri.recordcount
%>
<option value="<%=gnegeri("id")%>" <%if gnegeri("id") = session("negeri") then response.Write("selected") end if%>>
<%=gnegeri("nama_negeri")%></option>

lmf232s
04-28-2006, 01:36 PM
This code looks fine.
Check the Code where your setting your session variable.
Are you setting the session before you submit the page or after you submit the page?

When you refresh the page is the page just posting back or are you redirecting back to the same page. If you just posting back to the page then you wont need to use a session variable.

If you post some more of your code it might be easier to see where the problem is.

1 last thing, do a response.write Session("negeri") and see what the value is before you drop into your <select> loop. This will help see if you session value is even set to anything.

If gnegeri("id") is an integer then you might have a problem of trying to compage an integer to a string. So then this might help

If might also be that your comparing an integer to a string so you might want to convert the session to somehthing like cdbl(Session("negeri") in the If then statement.