Hay,
I think there's a slight bug when it comes to setting the selectedvalue
of serveral *dynamicly filled* listboxes.
Its like this:
Have a page with 5 dropdownlist boxes
fill them with 5 items as displayed below
Dim i As Integer = 0
For i = 1 To 5
Dim li As New ListItem
li.Text = i
li.Value = i
DropDownList1.Items.Add(li)
DropDownList2.Items.Add(li)
DropDownList3.Items.Add(li)
DropDownList4.Items.Add(li)
DropDownList5.Items.Add(li)
Next
After that, I want to have each of them select a different item, code
DropDownList1.SelectedValue = "1"
DropDownList2.SelectedValue = "2"
DropDownList3.SelectedValue = "3"
DropDownList4.SelectedValue = "4"
DropDownList5.SelectedValue = "5"
What really happens in this case, when it sets
DropDownList1.SelectedValue to "1", it sets ALL dropdownlists to "1",
same for "2", "3" etc.
It constantly sets all dropdownlists instead of just one
This doesnt happen when the dropdownlist is hard filled.
I can probably think of some javascript workaround, but this is still a
bit odd behaviour. 2 1106
Hay,
I think there's a slight bug when it comes to setting the selectedvalue
of serveral *dynamicly filled* listboxes.
Its like this:
Have a page with 5 dropdownlist boxes
fill them with 5 items as displayed below
Dim i As Integer = 0
For i = 1 To 5
Dim li As New ListItem
li.Text = i
li.Value = i
DropDownList1.Items.Add(li)
DropDownList2.Items.Add(li)
DropDownList3.Items.Add(li)
DropDownList4.Items.Add(li)
DropDownList5.Items.Add(li)
Next
After that, I want to have each of them select a different item, code
DropDownList1.SelectedValue = "1"
DropDownList2.SelectedValue = "2"
DropDownList3.SelectedValue = "3"
DropDownList4.SelectedValue = "4"
DropDownList5.SelectedValue = "5"
What really happens in this case, when it sets
DropDownList1.SelectedValue to "1", it sets ALL dropdownlists to "1",
same for "2", "3" etc.
It constantly sets all dropdownlists instead of just one
This doesnt happen when the dropdownlist is hard filled.
I can probably think of some javascript workaround, but this is still a
bit odd behaviour.
What I think happens is this:
When you set DropDownList1.SelectedValue = "1", that dropdownlist
searches through it's ListItems for a matching Value. When it has found
one, it sets the "Selected" property of that listitem to True.
BUT: as you have added that single listitem to *all* dropdowns, it gets
set everywhere.
Solution: fill each dropdownlist separately.
By the way: ListItem has a constructor where you can set Text and Value
immediately.
Hans Kesting
Hans is right. you only have 1 instance of your listitems per value.
Setting SelectedValue uses a list.Items.FindByValue(value), which enumerates
through the ListItem collection. This is a simple manner of how references
work in general purposes language.
Karl
-- http://www.openmymind.net/ http://www.codebetter.com/
"Hans Kesting" <ne***********@spamgourmet.comwrote in message
news:mn***********************@spamgourmet.com...
>Hay, I think there's a slight bug when it comes to setting the selectedvalue of serveral *dynamicly filled* listboxes. Its like this: Have a page with 5 dropdownlist boxes fill them with 5 items as displayed below
Dim i As Integer = 0 For i = 1 To 5 Dim li As New ListItem li.Text = i li.Value = i DropDownList1.Items.Add(li) DropDownList2.Items.Add(li) DropDownList3.Items.Add(li) DropDownList4.Items.Add(li) DropDownList5.Items.Add(li) Next
After that, I want to have each of them select a different item, code DropDownList1.SelectedValue = "1" DropDownList2.SelectedValue = "2" DropDownList3.SelectedValue = "3" DropDownList4.SelectedValue = "4" DropDownList5.SelectedValue = "5"
What really happens in this case, when it sets DropDownList1.SelectedValue to "1", it sets ALL dropdownlists to "1", same for "2", "3" etc. It constantly sets all dropdownlists instead of just one This doesnt happen when the dropdownlist is hard filled.
I can probably think of some javascript workaround, but this is still a bit odd behaviour.
What I think happens is this:
When you set DropDownList1.SelectedValue = "1", that dropdownlist searches
through it's ListItems for a matching Value. When it has found one, it
sets the "Selected" property of that listitem to True.
BUT: as you have added that single listitem to *all* dropdowns, it gets
set everywhere.
Solution: fill each dropdownlist separately.
By the way: ListItem has a constructor where you can set Text and Value
immediately.
Hans Kesting
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Dan |
last post by:
Can anyone offer suggestions on how to do this or if it is possible?
I have a form that uses a drop down box and 2 text fields.
What I am trying to do is have the value of each text box set by...
|
by: McKirahan |
last post by:
Firefox does not reflect selected option via innerHTML
How do I get Firefox to reflect selected option values?
<html>
<head>
<title>FFinner.htm</title>
<script type="text/javascript">...
|
by: Zlatko Matić |
last post by:
There is a form (single form) and a combobox. I want that current record of
the form is adjusted according to selected value in the combobox. Cuurrent
record should be the same as the value in the...
|
by: ajos |
last post by:
Hello friends,
After thinking about this for sometime, i decided to post this in the java forum.
Well my problem here in detail is, i have 3 jsp pages where in a.jsp(for example) i have a combo...
|
by: angelicdevil |
last post by:
i have listbox 1 which displays status , based on selection of status listbox 2 displays usernames. and based on username selected the textbox displays the email id.
its working fine till...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |