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

Reply via email to