473,382 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Dynamically selecting a value in a listbox from a passed variable

Hi,

I have a dynamically created listbox. I'm trying to get one of the
options selected according to a passed value. This is what i have:

<select name="txtTheme" id="txtTheme">

<option>Select Theme</option>
<%
Dim PassedTheme
Dim PickThis
PassedTheme = Request("txtTheme") %>
<% While (NOT RsThemes.EOF)%>

<% If Not rsChosenEvent.EOF Or Not rsChosenEvent.BOF Then %><% If
PassedTheme = (RsChosenEvent.Fields.Item("Theme").Value) Then Pickthis
= " SELECTED " %><% End IF %>

<option <%= PickThis %>
value="<%=(RsThemes.Fields.Item("ThemeID").Value)% >"><%=(RsThemes.Fields.Item("ThemeName").Value)% ></option>
<%
RsThemes.MoveNext()
Wend
If (RsThemes.CursorType > 0) Then
RsThemes.MoveFirst
Else
RsThemes.Requery
End If
%>

but for some reason PickThis is never writes " SELECTED " in the HTML
when it sould (i.e when Request("txtTheme") =
(RsChosenEvent.Fields.Item("Theme").Value)). I can't see why this
shouldn't work. Does anyone know how i can do this/workaround this?
Jul 19 '05 #1
5 2048
Have you response.Written Request("txtTheme") to verify the value?

Is it a text value or numeric? It seems you are not using the ThemeID field
to pass the theme. Why?

Instead of Request("txtTheme"), please use Request.Querystring("txtTheme")
(or Request.Form, Request.Cookies...... Point being, specify what you mean.
(http://www.aspfaq.com/show.asp?id=2111)

And may I suggest a bit different code:

<select name="txtTheme" id="txtTheme">

<option>Select Theme</option>
<%
Dim PassedTheme
Dim PickThis
Dim bMatch, sValue, sDisplay

PassedTheme = Request.QUERYSTRING("txtTheme")

While Not RsThemes.EOF
sValue = RsThemes.Fields.Item("ThemeID").Value
sDisplay = RsThemes.Fields.Item("ThemeName").Value
bMatch = RsThemes.Fields.Item("Theme").Value = PassedTheme
%>
<option value="<%=sValue%>"<% If bMatch Then Response.Write "
selected"%>><%=sDisplay%></option>
<%
RsThemes.MoveNext()
Wend
%>

Ray at home

"Lukelrc" <lu*********@westoxon.gov.uk> wrote in message
news:20*************************@posting.google.co m...
Hi,

I have a dynamically created listbox. I'm trying to get one of the
options selected according to a passed value. This is what i have:

<select name="txtTheme" id="txtTheme">

<option>Select Theme</option>
<%
Dim PassedTheme
Dim PickThis
PassedTheme = Request("txtTheme") %>
<% While (NOT RsThemes.EOF)%>

<% If Not rsChosenEvent.EOF Or Not rsChosenEvent.BOF Then %><% If
PassedTheme = (RsChosenEvent.Fields.Item("Theme").Value) Then Pickthis
= " SELECTED " %><% End IF %>

<option <%= PickThis %>
value="<%=(RsThemes.Fields.Item("ThemeID").Value)% >"><%=(RsThemes.Fields.Ite
m("ThemeName").Value)%></option> <%
RsThemes.MoveNext()
Wend
If (RsThemes.CursorType > 0) Then
RsThemes.MoveFirst
Else
RsThemes.Requery
End If
%>

but for some reason PickThis is never writes " SELECTED " in the HTML
when it sould (i.e when Request("txtTheme") =
(RsChosenEvent.Fields.Item("Theme").Value)). I can't see why this
shouldn't work. Does anyone know how i can do this/workaround this?

Jul 19 '05 #2
Hi,

I had tried to simplify my problem for the ease of explanation but I’ll
try to explain it now:

I have a site in which users can add an update to a list of events in
their area. When the user wishes to update an event they select an event
from a list and are taken to an ‘update page’ populated by a recordset
named rsChosenEvent. One of the fields in rsChosenEvents is themes. So
on the update page I have a list box populated by rsThemes which has
values set as rsThemes.ThemeID.value and the label as
rsThemes.ThemeName.value. So initially the theme is selected by:

<% If Not rsChosenEvent.EOF Or Not rsChosenEvent.BOF Then %><% If
(RsThemes.Fields.Item("ThemeID").Value) =
(RsChosenEvent.Fields.Item("Theme").Value) Then
Response.write("SELECTED ") %><% End IF %>

This is all fine and all works. What complicates matters is that I need
a button next to the themes listbox which takes users to a ‘theme adding
page’ in which they can add new themes. When they browse back to the
update page again I need all of the values that they had already updates
to be intact. So what I have done is added a group of hidden fields to
the theme adding page which carry the fields values back to the update
page again. At this point the rsChosenEvents is empty and the update
page is now populate dby the values passed from the hidden fields. So
now I need to slect a theme by something along the lines of:

<% if Request(“txtTheme”) = (RsThemes.Fields.Item("ThemeID").Value) then
response.write(“ SELECTED “) %> but if I put this inside the option tags
it never works.

This is the code I have at the moment which I’ve tried playing with:

<select name="txtTheme" id="txtTheme" style="width:120px;">
<option>Select Theme</option>
<%
Dim PassedTheme
Dim PickThis
PassedTheme = Request("txtTheme") %>
<% While (NOT RsThemes.EOF)%>
<% If Not rsChosenEvent.EOF Or Not rsChosenEvent.BOF Then %><% If
PassedTheme = (RsChosenEvent.Fields.Item("Theme").Value) Then Pickthis =
" SELECTED " %><% End IF %>

<option <% If Not rsChosenEvent.EOF Or Not rsChosenEvent.BOF Then %><%
If (RsThemes.Fields.Item("ThemeID").Value) =
(RsChosenEvent.Fields.Item("Theme").Value) Then
Response.write("SELECTED ") %><% End IF %><%= PickThis %><%IF
(RsThemes.Fields.Item("ThemeID").Value) = PassedTheme Then Choosethis =
" SELECTED " End IF %> <%= ChooseThis %>
value="<%=(RsThemes.Fields.Item("ThemeID").Value)% >"><%=(RsThemes.Fields
..Item("ThemeName").Value)%></option>
<%
RsThemes.MoveNext()
Wend
If (RsThemes.CursorType > 0) Then
RsThemes.MoveFirst
Else
RsThemes.Requery
End If
%>
</select>

I hope my explanation is clear enough. Do you have any idea why this
doesn’t work?

Thanks, Luke
*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #3
Have you response.Written Request("txtTheme") to verify the value?

Is it a text value or numeric? It seems you are not using the ThemeID field
to pass the theme. Why?

Ray at work

"Luke Curtis" <lu*********@westoxon.gov.uk> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi,

I had tried to simplify my problem for the ease of explanation but I'll
try to explain it now:

I have a site in which users can add an update to a list of events in
their area. When the user wishes to update an event they select an event
from a list and are taken to an 'update page' populated by a recordset
named rsChosenEvent. One of the fields in rsChosenEvents is themes. So
on the update page I have a list box populated by rsThemes which has
values set as rsThemes.ThemeID.value and the label as
rsThemes.ThemeName.value. So initially the theme is selected by:

<% If Not rsChosenEvent.EOF Or Not rsChosenEvent.BOF Then %><% If
(RsThemes.Fields.Item("ThemeID").Value) =
(RsChosenEvent.Fields.Item("Theme").Value) Then
Response.write("SELECTED ") %><% End IF %>

This is all fine and all works. What complicates matters is that I need
a button next to the themes listbox which takes users to a 'theme adding
page' in which they can add new themes. When they browse back to the
update page again I need all of the values that they had already updates
to be intact. So what I have done is added a group of hidden fields to
the theme adding page which carry the fields values back to the update
page again. At this point the rsChosenEvents is empty and the update
page is now populate dby the values passed from the hidden fields. So
now I need to slect a theme by something along the lines of:

<% if Request("txtTheme") = (RsThemes.Fields.Item("ThemeID").Value) then
response.write(" SELECTED ") %> but if I put this inside the option tags
it never works.

This is the code I have at the moment which I've tried playing with:

<select name="txtTheme" id="txtTheme" style="width:120px;">
<option>Select Theme</option>
<%
Dim PassedTheme
Dim PickThis
PassedTheme = Request("txtTheme") %>
<% While (NOT RsThemes.EOF)%>
<% If Not rsChosenEvent.EOF Or Not rsChosenEvent.BOF Then %><% If
PassedTheme = (RsChosenEvent.Fields.Item("Theme").Value) Then Pickthis =
" SELECTED " %><% End IF %>

<option <% If Not rsChosenEvent.EOF Or Not rsChosenEvent.BOF Then %><%
If (RsThemes.Fields.Item("ThemeID").Value) =
(RsChosenEvent.Fields.Item("Theme").Value) Then
Response.write("SELECTED ") %><% End IF %><%= PickThis %><%IF
(RsThemes.Fields.Item("ThemeID").Value) = PassedTheme Then Choosethis =
" SELECTED " End IF %> <%= ChooseThis %>
value="<%=(RsThemes.Fields.Item("ThemeID").Value)% >"><%=(RsThemes.Fields
Item("ThemeName").Value)%></option>
<%
RsThemes.MoveNext()
Wend
If (RsThemes.CursorType > 0) Then
RsThemes.MoveFirst
Else
RsThemes.Requery
End If
%>
</select>

I hope my explanation is clear enough. Do you have any idea why this
doesn't work?

Thanks, Luke
*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 19 '05 #4
Like i said,

Its Numeric, and if i response.write("txtTheme") i get the correct
value.

It is the ThemeID that is passed. I.e txtTheme's value is ThemeID and
its Label is ThemeName.

Luke

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #5
But what you're using the check for a match is the theme name, not the ID.
I suggest that you pass the theme ID in the querystring and try this code:

sample url:
/yourpage.asp?themeid=3

<select name="txtTheme" id="txtTheme">

<option>Select Theme</option>
<%
Dim iPassedTheme
Dim PickThis
Dim bMatch, iThemeID, sDisplay

iPassedTheme = "0" & Request.QUERYSTRING("themeID")
If Not IsNumeric(iPassedTheme) Then iPassedTheme = 0

While Not RsThemes.EOF
iTheme = RsThemes.Fields.Item("ThemeID").Value
sDisplay = RsThemes.Fields.Item("ThemeName").Value
bMatch = CInt(iThemeID) = CInt(iPassedTheme)
%>
<option value="<%=sValue%>"<% If bMatch Then Response.Write "
selected"%>><%=sDisplay%></option>
<%
RsThemes.MoveNext()
Wend
%>

Ray at work

"Luke Curtis" <lu*********@westoxon.gov.uk> wrote in message
news:eJ**************@TK2MSFTNGP12.phx.gbl...
Like i said,

Its Numeric, and if i response.write("txtTheme") i get the correct
value.

It is the ThemeID that is passed. I.e txtTheme's value is ThemeID and
its Label is ThemeName.

Luke

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Randell D. | last post by:
HELP! I am determined to stick with this... I'm getting there... for those who haven't read my earlier posts, I'm createing what should be a simple function that I can call to check that...
6
by: NotGiven | last post by:
I want to learn moer of what I saw in a recent example. They create a page that created new fields/element. It's not like they were hidden and they displayed them, they were not there, then the...
2
by: Remco Groot Beumer | last post by:
Hello, I created a program in which I use modules and classmodules for setting my variables. For example when I need to set the customerID in a variable I use something like: ...
19
by: daniel | last post by:
This is a pretty basic-level question, but I'd really like to know, so thanks for any help or pointers you can provide (like what I would google for ;o) Suppose: <code> myFunc() {
1
by: Reza Nabi | last post by:
Bakground: I have a webform (LoadCtl.aspx) which loads the user control to a placeholder dynamically based on the ctlName querystring passed in the URL. Webform (LoadCtl.aspx) also passes a...
5
by: sfeher | last post by:
Hi All, I need to call a function(loaded with appendChild) for which I have the name as a string. .... var fnName = 'fn1'; var call = fnName + '('+ param +' )'; eval(call);
4
by: assgar | last post by:
Hi I am stuck on a problem. I use 3 scripts(form, function and process). Development on win2003 server. Final server will be linux Apache,Mysql and PHP is being used. The form displays...
6
by: GS | last post by:
how can I set tooTip on ToolTip1 for a listbox?
0
by: =?Utf-8?B?UGF1bA==?= | last post by:
I have a ListBox server control named "lb_dates" with a SelectionMode of "Multiple". The user can select multiple dates from the listbox. I have ObjectDataSource named "ods_rfq" with a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.