CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2004
    Location
    Toronto, Canada
    Posts
    108

    Multi-Select ListBox Problem

    Greetings:

    I have a simple ListBox with multiselect enabled in an ASP.NET 2.0 WEB project. The box has about 10 items in it and to test, I selected items 1 and 5 (index base 0). Both items in the box are highlighted as you would expect. Also, I checked to ensure that view state was enabled for the list box.

    Then, I execute this code straight out of MS-help to determine which items where selected:

    int nNumSel = 0;
    foreach(ListItem li in ListBox1.Items)
    {
    if(li.Selected == true)
    {
    nNumSel++;
    }
    }

    Stepping through this, I am finding that only the 1st selected item is recognized as being selected. The item at index 5 is reporting "false" for its "Selected" property. Why? What have I missed?

    Thanks to anybody that responds.
    Mark

  2. #2
    Join Date
    Jul 2008
    Posts
    21

    Re: Multi-Select ListBox Problem

    Please check whether there is a post back in the page load event. May be this would be the cause.

  3. #3
    Join Date
    Apr 2004
    Location
    Toronto, Canada
    Posts
    108

    Re: Multi-Select ListBox Problem

    Hi, thanks for responding.

    Not sure what you mean, exactly. Are you talking about checking for whether or not the page is being loaded for the "first time" or as a result of a postback using the "IsPostback" property? Or something else?

    The one thing that I wanted to stress was that I am selecting TWO items and it is always detecting the first one, it just isn't seeing the other selections. That is, the "Selected" property is true only for the first selected item.

    Cheers,
    Mark

  4. #4
    Join Date
    Jul 2008
    Posts
    21

    Re: Multi-Select ListBox Problem

    Hi,

    Please check that while your selection is getting checked is the data in the listbox is getting refreshed. I mean as you are checking for the selected items in the list, is the list doing a postback. And in that case you can check whether in the page load event have you bound the data to the listbox without handling the postback event. I hope this would solve the problem.

    Regards,

    Pintu

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured