Select loop

8 posts, 1 answers
  1. Alex Lawson
    Alex Lawson avatar
    43 posts
    Member since:
    May 2008

    Posted 20 Jul 2009 Link to this post

    I have upgraded a listbox to the new verison, looks good but there is an issue with the selected flag.

    Scenario: The list box has 2 items (a & b).  I have selected item a via a mouse click and clicked the transfer button, then run the following code:

            protected void lbxAssigned_Transferred(object sender, RadListBoxTransferredEventArgs e) 
            { 
                foreach (RadListBoxItem listItem in lbxAvailable.Items) 
                { 
                    if (listItem.Selected) 
                    { 
                        ProductCarriers objPC = new ProductCarriers(); 
                        string test = listItem.Text; 
                        objPC.Allocate(Convert.ToInt32(listItem.Value), Convert.ToInt32(cbxProducts.SelectedValue)); 
                    } 
                } 
                PopulateLists(); 
            } 

    However when I debug the loop the first iteration (item a) passes the selection check, but the listitem.text and listitem.value are from item b.

    I will attempt to code this another way for the moment, thought you would want to be aware.

    Thanks,
    Lee




  2. ManniAT
    ManniAT avatar
    877 posts
    Member since:
    Nov 2003

    Posted 20 Jul 2009 Link to this post

    Hi Alex,

    to be sure that I understood what you explained.
    You have 2 listboxe - the first has two items and is named lbAvailable - the second is named lbxAssigned.
    So at the start it looks like this
    lbAvailable         lbxAssigned
    a
    b

    After you transfer it looks like:
    lbAvailable         lbxAssigned
    b                          a

    Markup (I know you are databound) may look like this:
    <telerik:RadListBox ID="lbAvailable" runat="server" AllowTransfer="true" TransferMode="Move" TransferToID="lbxAssigned" > 
    <Items> 
    <telerik:RadListBoxItem runat="server" Value="1" Text="a" /> 
    <telerik:RadListBoxItem runat="server" Value="2" Text="b" /> 
    </Items> 
    </telerik:RadListBox> 
    <telerik:RadListBox ID="lbxAssigned" runat="server" ontransferred="lbxAssigned_Transferred">  
    <Items> 
    </Items> 
    </telerik:RadListBox> 
     
    If this is correct - your code - and the RadListboxes work like they should!!
    In your code which handles the transfer to lbxAssigned - you query what is in lbxAvailable.
    And this is item B which gets selected after item I is transfered.
    --(check in the samples or remove "autoupdate" temporarily) you will see that the "next item" is selected.

    So what you get is what it is - you query item b from the first (lbAvailable) listbox.
    Try to iterate through lbxAssigned - now you should get item a (not selected).

    Regards

    Manfred
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Alex Lawson
    Alex Lawson avatar
    43 posts
    Member since:
    May 2008

    Posted 20 Jul 2009 Link to this post

    Ah I see, thanks - evidentally I have picked the wrong event.

    I would have expected to selected flag to be cleared after transferred has fired though :)
  5. ManniAT
    ManniAT avatar
    877 posts
    Member since:
    Nov 2003

    Posted 20 Jul 2009 Link to this post

    Hi,

    not the wrong event -- the wrong listbox.

    foreach(.....in lbxAvailable)...
    should be
    foreach(.....in lbxAssigned)

    And by the way (regarding to your sample) - b (or in general a newly transfered item) is NOT selected.

    Cheers

    Manfred
    PS: If this solved your problem - please mark the post as answer.
  6. Alex Lawson
    Alex Lawson avatar
    43 posts
    Member since:
    May 2008

    Posted 20 Jul 2009 Link to this post

    No this is the correct listbox in the context of what the code is trying to achieve, this is legacy code I am trying to upgrade to the Telerik Listbox, unfortunatly the telerik listbox does not seem to behave as per the control set I am trying to replace therefore I will recode the whole thing.

    Thanks,
    Lee
  7. Answer
    ManniAT
    ManniAT avatar
    877 posts
    Member since:
    Nov 2003

    Posted 20 Jul 2009 Link to this post

    Hi Lee,

    sorry about that "wrong listbox" - since you didn't argue about my first post I thought my (assumed) code was fitting your situation.

    Cheers

    Manfred
  8. Alex Lawson
    Alex Lawson avatar
    43 posts
    Member since:
    May 2008

    Posted 20 Jul 2009 Link to this post

    No problem, I have fixed my code by simply looping through the RadListBoxTransferredEventArgs.items instead.  I hate legacy code but it has to be done.

    Thanks for your help.
  9. ManniAT
    ManniAT avatar
    877 posts
    Member since:
    Nov 2003

    Posted 20 Jul 2009 Link to this post

    I hate legacy code too - but currently I have positive feelings about it.
    My current project is to "rebuild" a .NET 1.x (yes ONE) datalist, datarepeater project to 3.5 with telerik controls.
    Every phone call with my customer makes me happy :)
    Oh great, so fast, so beautiful...oh, it automatically handles that error, aah, the page does not reload when i save...
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017