473,326 Members | 2,090 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,326 software developers and data experts.

Two DropDownLists getting crossed

Jay
I'm having a weird problem in ASP.NET 1.1. I have two DropDownLists in
a form. Both lists are build identically but separately. Somehow the
DropDownLists are getting crossed in memory, because when I set the
SelectedValue for the second list, the first list's SelectedValue
becomes set to the SelectedValue of the second list.

I'm also getting this exception during the render process: "A
DropDownList cannot have multiple items selected." I'm pretty sure this
is related to this problem.

The DDLs are named ddlSupervisorID1 and ddlSupervisorID2. Yes, I am
assigning the second supervisor before the first supervisor. This helps
illustrate the problem better. I'm having the same problem when the
first supervisor is assigned first.)

Any assistance is appreciated.

[begin output]
A: S1 = 0 | S2 = 0
S2: S1 = 0 | S2 = 4787
S1: S1 = 919 | S2 = 919
[end output]

[begin assignment code]

Trace.Write(ID, "A: S1 = " & ddlSupervisorID1.SelectedValue & " | S2 =
" & ddlSupervisorID2.SelectedValue)

'_ Supervisor2
ddlSupervisorID2.SelectedValue = data("SupervisorID2")
Trace.Write(ID, "S2: S1 = " & ddlSupervisorID1.SelectedValue & " | S2 =
" & ddlSupervisorID2.SelectedValue)

'_ Supervisor1
ddlSupervisorID1.SelectedValue = data("SupervisorID1")
Trace.Write(ID, "S1: S1 = " & ddlSupervisorID1.SelectedValue & " | S2 =
" & ddlSupervisorID2.SelectedValue)

[end assignment code]

[begin list construction code]

For Each dr As DataRow In dtAssociates
Dim sKey As String = dr("AssociateNameLF") & " (#" &
dr("AssociateID") & ")"
Dim li As New ListItem(sKey, dr("AssociateID"))
ddlAssociateID.Items.Add(li)
If dr("IsSupervisor") Then
ddlSupervisorID1.Items.Add(li)
ddlSupervisorID2.Items.Add(li)
End If
Next

[end list construction code]

Nov 19 '05 #1
2 1199
You only created ONE ListItem, but tried to add it to 3 dropdown list. You
should create ListItem for each Dropdownlist:

For Each dr As DataRow In dtAssociates
Dim sKey As String = dr("AssociateNameLF") & " (#" &
dr("AssociateID") & ")"
Dim li As ListIten

li=New ListItem(sKey, dr("AssociateID"))
ddlAssociateID.Items.Add(li)

If dr("IsSupervisor") Then

li=New ListItem(sKey, dr("AssociateID"))
ddlSupervisorID1.Items.Add(li)

li=New ListItem(sKey, dr("AssociateID"))
ddlSupervisorID2.Items.Add(li)

End If
Next
"Jay" <sp**@bienvenu.net> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
I'm having a weird problem in ASP.NET 1.1. I have two DropDownLists in
a form. Both lists are build identically but separately. Somehow the
DropDownLists are getting crossed in memory, because when I set the
SelectedValue for the second list, the first list's SelectedValue
becomes set to the SelectedValue of the second list.

I'm also getting this exception during the render process: "A
DropDownList cannot have multiple items selected." I'm pretty sure this
is related to this problem.

The DDLs are named ddlSupervisorID1 and ddlSupervisorID2. Yes, I am
assigning the second supervisor before the first supervisor. This helps
illustrate the problem better. I'm having the same problem when the
first supervisor is assigned first.)

Any assistance is appreciated.

[begin output]
A: S1 = 0 | S2 = 0
S2: S1 = 0 | S2 = 4787
S1: S1 = 919 | S2 = 919
[end output]

[begin assignment code]

Trace.Write(ID, "A: S1 = " & ddlSupervisorID1.SelectedValue & " | S2 =
" & ddlSupervisorID2.SelectedValue)

'_ Supervisor2
ddlSupervisorID2.SelectedValue = data("SupervisorID2")
Trace.Write(ID, "S2: S1 = " & ddlSupervisorID1.SelectedValue & " | S2 =
" & ddlSupervisorID2.SelectedValue)

'_ Supervisor1
ddlSupervisorID1.SelectedValue = data("SupervisorID1")
Trace.Write(ID, "S1: S1 = " & ddlSupervisorID1.SelectedValue & " | S2 =
" & ddlSupervisorID2.SelectedValue)

[end assignment code]

[begin list construction code]

For Each dr As DataRow In dtAssociates
Dim sKey As String = dr("AssociateNameLF") & " (#" &
dr("AssociateID") & ")"
Dim li As New ListItem(sKey, dr("AssociateID"))
ddlAssociateID.Items.Add(li)
If dr("IsSupervisor") Then
ddlSupervisorID1.Items.Add(li)
ddlSupervisorID2.Items.Add(li)
End If
Next

[end list construction code]

Nov 19 '05 #2
Jay
Is there a cleaner way to do this? Copying the line "li=New
ListItem(sKey, dr("AssociateID"))" will clutter the code unnecessarily.

Nov 19 '05 #3

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

Similar topics

0
by: theo | last post by:
Hello..I have a similar issue as yesterday but the situation has slightly changed so perhaps someone can shed some more light on the issue... Program flow - load file,extract xml text tags from...
1
by: Chris | last post by:
Hello All, Need some help here. I'm building an asp.net app that uses a datagrid. I have created a template column and added a dropdownlist to it. What I'd like to happen is have the database...
0
by: Steve Caliendo | last post by:
Hi, I'm having trouble with multiple dynamically generated dropdownlists. On my web page I have several text boxes / labels / checkboxes and dropdownlists I have no problem setting the other...
9
by: Timm | last post by:
I have an ASP.NET 2.0 page with two DropDownLists. I am using declarative data binding wherever possible and trying to minimize the use of code. The list of values in DropDownList DDL2 should be...
2
by: Italian Pete | last post by:
Hi, I have some dropdownlist web controls on as aspx page. I want to loop through them on first (!IsPostBack) Page_Load in order to populate them. The foreach control structure seems to be a good...
8
by: MattB | last post by:
I have a asp.net 1.1/vb application that has a page with a bunch of dynamically added User Controls. When I add the controls, I set the UserControl.EnableViewState to true. For all my controls...
0
by: Carlos | last post by:
Hi all, I just embedded a dropdownlist templatefield inside a gridview. When I look at the control in design mode, I see 5 dropdownlists, when I bind the data to the gridview, I only bind to 3...
3
by: RSH | last post by:
Hi, I am having this very bizarre occurance with 4 dropdown lists on my ASP .Net page. Each control has its own unique id. When the user selects a value from each of the dropdownlists it is...
1
by: klaul | last post by:
I've been trying to do this for a day and a half now, and am clearly getting nowhere! The database I'm using is used to keep a log of service calls to various companies. When the user inserts data,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.