
Please Help with passing listbox <select multiple> values in asp vbscript
Will you post the entire page as an attachment along with a description of
the fields in the database? I am referring to the page that builds the
dynamic list and the one presents the originally selected values to the
user.
--Ryan N.
Quote:
> This one did not get an error and values are populated from database, but
> now I am back to the beginning: originally selected values do not stay
> selected upon server.transfer back to this page...
> If that's is any help, here is how I am creating that recordset:
> <%
> set rsRegions = Server.CreateObject("ADODB.Recordset")
> rsRegions.ActiveConnection = MY_DBOCONNECTION_STRING ' from include
file
> rsRegions.Source = "SELECT RegionID, Description FROM dbo.Regions ORDER BY
> RegionID ASC"
> rsRegions.CursorType = 0
> rsRegions.CursorLocation = 2
> rsRegions.LockType = 3
> rsRegions.Open()
> rsRegions_numRows = 0
> %>
> I am a little lost now... If my values in the listbox created dynamically
by
> calling recordset, then how can be
> > more records in the recordset than items in the form collection?
> or I am missing something in your explanation?
> Thanks anyway for helping me out and your time.
> George
> > hmmm...you are receiving that error because there are more records in
the
> > recordset than items in the form collection. Attached is a modified-but
> not
> > tested-version of the example code that checks whether the iIndex
variable
> > is less than or equal to the form collection count before trying to
access
> > an item in the collection.
> > Give it a whirl and let us know if you require further assistance.
> > --Ryan N.
> > > Got your code, thanks. But same array index error. I am running IIS
5.1
> > with
> > > msde 2000.
> > > George
> > > > Darn the word e-mail client word wrap. I have attached the sample
> code
> > > for
> > > > you-hope your NNTP client supports attachments and the formatting
> > doesn't
> > > > change.
> > > > What version of IIS are you running?
> > > > --Ryan N.
> > > > > Ryan, I am getting syntax error for
> > > > > > If
CINT(rsRegions.Fields("RegionID"))=CINT(Request.Form("Regions")(iIndex))
Quote:
> > > > > > Then
> > > > > Placing them on single line:
> > > > > > If
> > CINT(rsRegions.Fields("RegionID"))=CINT(Request.Form("Regions")(iIndex))
> > > > > Then
> > > > > gives me an array error for same line number:
> > > > > Request object, ASP 0105 (0x80004005)
> > > > > An array index is out of range.
> > > > > Any idea why?
> > > > > Thanks
> > > > > George
> > > > > > Replace your code example with the following:
> > > > > > <select name="Regions" size="5" multiple>
> > > > > > <%
> > > > > > Dim iIndex : iIndex=1
> > > > > > While NOT rsRegions.EOF
> > > > > > If
CINT(rsRegions.Fields("RegionID"))=CINT(Request.Form("Regions")(iIndex))
Quote:
> > > > > > Then
> > > > > > %>
> > > > > > <option selected
value="<%=rsRegions.Fields("RegionID")%>"><%=rsRegions.Fields("Description"
)
Quote:
> > > > > > %></option>
> > > > > > <%
> > > > > > Else
> > > > > > %>
> > > > > > <option
value="<%=rsRegions.Fields("RegionID")%>"><%=rsRegions.Fields("Description")
Quote:
> > > > > > %></option>
> > > > > > <%
> > > > > > End If
> > > > > > rsRegions.MoveNext
> > > > > > iIndex=iIndex+1
> > > > > > Wend
> > > > > > If rsRegions.CursorType > 0 Then
> > > > > > rsRegions.MoveFirst
> > > > > > Else
> > > > > > rsRegions.Requery
> > > > > > End If
> > > > > > %>
> > > > > > </select>
> > > > > > --Ryan N.
> > > > > > > Thanks Ryan, but it did not help. Same result, my listbox is
> > empty.
> > > As
> > > > > > soon
> > > > > > > as "For x=1 to Request.Form("Regions").count" comes into play
> > values
> > > > > from
> > > > > > > database are not coming through...
> > > > > > > George
> > > > > > > > Try changing the following line:
> > > > > > > > If CINT(rsRegions.Fields("RegionID")) =
> > > Request.Form("Regions")(x)
> > > > > > Then
> > > > > > > > to:
> > > > > > > > If CINT(rsRegions.Fields("RegionID")) =
> > > > > > CINT(Request.Form("Regions")(x))
> > > > > > > > Then
> > > > > > > > Also change:
> > > > > > > > rsRegions.MoveNext()
> > > > > > > > To rsRegions.MoveNext
> > > > > > > > Let us know if you require more help.
> > > > > > > > --Ryan N.
> > > > > > > > > Hi fellows,
> > > > > > > > > Please help me to figure out what is wrong with my
script...
> > > > > > > > > My goal is to keep selected multiple choices from listbox
in
> > > case
> > > > if
> > > > > > > user
> > > > > > > > is
> > > > > > > > > transferred back (redirected) from the next page. I know
how
> > to
> > > > > > > accomplish
> > > > > > > > > it for dropdown menu, but with listbox I am kind of stuck.
I
> > am
> > > > > trying
> > > > > > > to
> > > > > > > > > use code below, but then my dynamically generated list
> values
> > > are
> > > > > > > > > disappearing on initial page load. If I to move first
> > > > > > > > > IF..Then..For..Next..Endif at the bottom of the page and
use
> > > > > > > > response.write,
> > > > > > > > > I'll get my values displayed. So I know it is right way to
> go
> > > > except
> > > > > > my
> > > > > > > > > logic with If ..Then is broken :(
> > > > > > > > > Thanks in advance.
> > > > > > > > > George
> > > > > > > > > <select name="Regions" size="5" multiple>
> > > > > > > > > <%
> > > > > > > > > While (NOT rsRegions.EOF)
> > > > > > > > > If Request.Form("Regions").count > 1 Then
> > > > > > > > > For x=1 to Request.Form("Regions").count
> > > > > > > > > If CINT(rsRegions.Fields("RegionID")) =
> > > > > Request.Form("Regions")(x)
> > > > > > > Then
> > > > > > > > > %>
> > > > > > > > > <option selected
> > > > > > value="<%=(rsRegions.Fields.Item("RegionID").Value)%>"
><%=(rsRegions.Fields.Item("Description").Value)%></option>
> > > > > > > > > <% ELSE %>
> > > > > > > > > <option
> value="<%=(rsRegions.Fields.Item("RegionID").Value)%>"
><%=(rsRegions.Fields.Item("Description").Value)%></option>
> > > > > > > > > <% End IF %>
> > > > > > > > > <% Next %>
> > > > > > > > > <% End IF %>
> > > > > > > > > <%
> > > > > > > > > rsRegions.MoveNext()
> > > > > > > > > Wend
> > > > > > > > > If (rsRegions.CursorType > 0) Then
> > > > > > > > > rsRegions.MoveFirst
> > > > > > > > > Else
> > > > > > > > > rsRegions.Requery
> > > > > > > > > End If
> > > > > > > > > %>
> > > > > > > > > </select>