Home All Groups Group Topic Archive Search About

Two DropDownLists getting crossed

Author
10 Jun 2005 7:27 PM
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]

Author
10 Jun 2005 7:39 PM
Norman Yuan
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


Show quoteHide quote
"Jay" <spam@bienvenu.net> wrote in message
news:1118431669.226338.218300@g44g2000cwa.googlegroups.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]
>
Are all your drivers up to date? click for free checkup

Author
10 Jun 2005 9:18 PM
Jay
Is there a cleaner way to do this? Copying the line "li=New
ListItem(sKey, dr("AssociateID"))" will clutter the code unnecessarily.

Bookmark and Share