Hi Ravi Thanks for the message. The values were unique. I actually solved the problem. It was that I needed to put the (if (! isPostBack) when the ListBox loads!! I was trying to account for the postback on the _Click method.
Thanks for all of your help though. Paul On Aug 12, 1:12 am, ravindra kumar <[email protected]> wrote: > Hi > > You have to asign the Listitems value and value should be unique otherwise > you get this problem. > > > > On Wed, Aug 11, 2010 at 1:32 AM, ptvvee <[email protected]> wrote: > > I'm a fairly junior .Net developer and am totally stumped on an > > issue. I have two applications and in one of them the exact same code > > works just fine, but I can't seem to get it to work in the second. I > > have created a multiple selection Listbox where I add the items > > programatically based on the values that exist in a database. Then, > > when I go to retrieve the selected items, the code keeps returning the > > first item to me even when I select other items. Here is my code: > > > string selectedStateValues = string.Empty; > > int stateCount = 0; > > foreach (ListItem li in lbLocation.Items) > > { > > if (li.Selected == true) > > { > > if (stateCount == 0) > > { > > selectedStateValues += li.Text; > > stateCount += 1; > > } > > else > > { > > selectedStateValues += " " + li.Text; > > } > > } > > } > > > The first item in the Listbox is "Show All" and then below that are > > various states like VA, MD, NY etc. Even if I select NY, the debugger > > shows that "Show All" is selected (when it isn't). I've got > > Autopostback set to True and have tried accounting for postback in the > > code, but nothing seems to work. Any help anyone could provide would > > be great. Thanks!! > > -- > Ravindra kumar > delhi
