Listbox move multiple selected items to second listbox

Discussion in 'ASP .Net' started by K B, Jan 7, 2007.

  1. K B

    K B Guest

    Hi, The following code has been successful for me in the past and i just
    can't figure out where I'm going wrong. When I debug I keep getting the
    two top items as selected even though there are not selected and the
    selected items are ignored. I'm using ASP.NET 2.0 and using two server
    listbox controls. Any help appreciated.
    Kit

    Dim item As ListItem
    Dim check As ListItem
    For Each item In lstSelect.Items
    If item.Selected = True Then
    'check if value already exists in lstTo
    check = lstTo.Items.FindByValue(item.Value)
    If Not check Is Nothing Then
    Exit Sub
    Else
    lstTo.Items.Add(New ListItem(item.Text, item.Value))
    End If
    End If
    Next



    *** Sent via Developersdex http://www.developersdex.com ***
     
    K B, Jan 7, 2007
    #1
    1. Advertising

  2. Your code works just fine here. Maybe a reboot will do you some good.

    --
    Regards,
    Alvin Bruney
    ------------------------------------------------------
    Shameless author plug
    Excel Services for .NET is coming...
    OWC Black book on Amazon and
    www.lulu.com/owc

    "K B" <> wrote in message
    news:%23$...
    > Hi, The following code has been successful for me in the past and i just
    > can't figure out where I'm going wrong. When I debug I keep getting the
    > two top items as selected even though there are not selected and the
    > selected items are ignored. I'm using ASP.NET 2.0 and using two server
    > listbox controls. Any help appreciated.
    > Kit
    >
    > Dim item As ListItem
    > Dim check As ListItem
    > For Each item In lstSelect.Items
    > If item.Selected = True Then
    > 'check if value already exists in lstTo
    > check = lstTo.Items.FindByValue(item.Value)
    > If Not check Is Nothing Then
    > Exit Sub
    > Else
    > lstTo.Items.Add(New ListItem(item.Text, item.Value))
    > End If
    > End If
    > Next
    >
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
     
    Alvin Bruney [MVP], Jan 8, 2007
    #2
    1. Advertising

  3. K B

    K B Guest

    Thanks, Alvin. I'm embarrased to say after HOURs of looking at it, that
    I realized my test database table had duplicate values...thereby
    throwing of the selected items. I hope this posting helps someone else
    some day.

    thanks again,
    kb



    *** Sent via Developersdex http://www.developersdex.com ***
     
    K B, Jan 8, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. kent
    Replies:
    1
    Views:
    909
    Andrew de la Harpe
    May 3, 2004
  2. Ryan Ternier
    Replies:
    0
    Views:
    480
    Ryan Ternier
    Oct 27, 2005
  3. Jason L Lind

    ListBox Programaticly Set Multiple Items as Selected

    Jason L Lind, Apr 11, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    151
    Jason L Lind
    Apr 11, 2006
  4. Adrian Forbes

    Remove multiple selected items listbox

    Adrian Forbes, Aug 7, 2003, in forum: ASP General
    Replies:
    0
    Views:
    138
    Adrian Forbes
    Aug 7, 2003
  5. rbr
    Replies:
    1
    Views:
    121
    Hal Rosser
    Sep 24, 2008
Loading...

Share This Page