Invoking method in OnTransferring based on selected button

5 posts, 0 answers
  1. Ronnie
    Ronnie avatar
    29 posts
    Member since:
    Oct 2008

    Posted 08 Oct 2009 Link to this post

    Hello,

    I have a manual implementation using asp:ListBoxes and asp:Buttons.  It also adds/removes an asp:DropDownList when transferring back and forth from the 2 ListBoxes.

    I'm converting it to use RadListBoxes and a RadComboBox.  Creating RadListBox1 and RadListBox2 and transferring between the 2 was simple enough.  Then I used the OnTransferring Event to invoke a method that will add and remove from RadComboBox1.  I have a couple of problems completing this:

    - How do I get access in OnTransferring (or other event) to the button selected... To Right(>), To Left(<), All to Right(>>), or All to Left(<<) ?
    - In what event, or how... can I invoke a "RemoveFromComboBox" method when selecting/moving back To Left, or All to Left ?

    Here's my code:
    <td><telerik:RadComboBox ID="RadComboBox1" runat="server" /></td>  
    <td>  
       <telerik:RadListBox ID="RadListBox1" runat="server" Height="200px" Width="200px"   
          AllowTransfer="true" TransferToID="RadListBox2"    
          AutoPostBackOnTransfer="true"  
          SelectionMode="Multiple" EnableDragAndDrop="true"   
          OnTransferring="RadListBox1_Transferring" />  
    </td>  
    <td>  
       <telerik:RadListBox ID="RadListBox2" runat="server" Height="200px" Width="200px"   
          AutoPostBackOnTransfer="true"  
          SelectionMode="Multiple" EnableDragAndDrop="true" />  
    </td> 

    and code-behind:

    protected void RadListBox1_Transferring(object sender, RadListBoxTransferringEventArgs e) 
       AddToDefaultComboBox(true); 
       RemoveFromDefaultComboBox(true);  // Needs to be in different event to return back to left. (maybe RadListBox2_Transferring).  But RadListBox2.AllowTransfer="false" ??? find solution. 

    // Adds item(s) to RadComboBox1 when transferring from RadListBox1 to RadListBox2
    private void AddToDefaultComboBox(bool all) 
       foreach (RadListBoxItem li in RadListBox1.Items) 
       { 
          if ((li.Selected) || (all)) 
          { 
             RadComboBox1.Items.Add(new RadComboBoxItem(li.Text, li.Value)); 
          } 
       } 
    }

    // Removes item(s) to RadComboBox1 when transferring from RadListBox2 to RadListBox1
    private void RemoveFromDefaultComboBox(bool all) 
       foreach (RadListBoxItem li in RadListBox2.Items) 
       { 
          if ((li.Selected) || (all)) 
          { 
             RadComboBox1.Items.Remove(RadComboBox1.Items.FindItemByValue(li.Value)); 
          } 
       } 

    I've tested these methods, and they do the job, but I need pass these 4 based on what's selected:
    1. AddToDefaultComboBox(false)             --> When selecting RadListBox1 item (to right >)
    2. AddToDefaultComboBox(true)              --> When selecting RadListBox1 items (all to right >>)
    3. RemoveFromDefaultComboBox(false) --> When selecting RadListBox2 item (< to left)
    4. RemoveFromDefaultComboBox(true)  -->  When selecting RadListBox2 items (<< all to left)

    I hope this makes sense and thank you in advance for reviewing this and any assistance.
    Ronnie


  2. Genady Sergeev
    Admin
    Genady Sergeev avatar
    1596 posts

    Posted 15 Oct 2009 Link to this post

    Hello Ronnie,

    It turned out that there is no easy way to find out on the server which button was pressed. I will try to find a workaround and will write a follow up tomorrow.

    Best wishes,
    Genady Sergeev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Genady Sergeev
    Admin
    Genady Sergeev avatar
    1596 posts

    Posted 19 Oct 2009 Link to this post

    Hello Ronnie,

    I have  prepared sample project that demonstrates how to find out which button was pressed and use that value on the server. The project is attached to this replay.

    Sincerely yours,
    Genady Sergeev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. Ronnie
    Ronnie avatar
    29 posts
    Member since:
    Oct 2008

    Posted 19 Oct 2009 Link to this post

    Hello Genady,

    Thank you for your time on this.  I'll give the sample a try.

    Thanks again,
    Ronnie
  6. Cary
    Cary avatar
    18 posts
    Member since:
    Feb 2008

    Posted 28 Jan 2010 Link to this post

    I know this is an old thread, but just in case anyone needs a solution I have what I consider to be an easy one.
    Standard setup of two Rad List Boxes, one setup with the transfer and modes, etc. Basically I have a Products, Tasks, and ProductTasks table.. The ProductTasks table facilitates a many to many relationship where we typically have more than one product in a task or visa versa.
                        <table class="pCell"
                            <tr> 
                                <td> 
                                    Products Not In Task 
                                </td> 
                                <td> 
                                    Products In Task 
                                </td> 
                            </tr> 
                            <tr> 
                                <td> 
                                    <telerik:RadListBox ID="rlbProductsNotInTask" runat="server"  
                                        AllowTransfer="true" TransferToID="rlbProductsInTask" Height="300px"  
                                        SelectionMode="Multiple" EnableDragAndDrop="true" DataTextField="ProductNumber"  
                                        DataValueField="ProductId" Width="250px" AutoPostBackOnTransfer="True"  
                                        ontransferred="rlbProductsNotInTask_Transferred" /> 
                                </td> 
                                <td> 
                                    <telerik:RadListBox ID="rlbProductsInTask" runat="server" Height="300px"  
                                        SelectionMode="Multiple" DataTextField="ProductNumber"  
                                        DataValueField="ProductId" Width="250px"  /> 
                                </td> 
                            </tr> 
                        </table> 

    The event arg contains a list of items being transfered into or out of the list, so what you need to do is create a list of items being transfered. Once you have that done you should make sure you have anything in the list, because users can click the button several times with nothing selected. If it does, the TransferToId will be set on one of your list boxes, just check to verify the ID and based on that you can determine if you are inserting or deleting from your link table.
            protected void rlbProductsNotInTask_Transferred(object sender, Telerik.Web.UI.RadListBoxTransferredEventArgs e) 
            { 
                int Id = Convert.ToInt32(Request.QueryString["id"]); 
                List<TaskProduct> list = new List<TaskProduct>(); 
                foreach (Telerik.Web.UI.RadListBoxItem lbi in e.Items) 
                { 
                    TaskProduct ptp = new TaskProduct(); 
                    ptp.ProductionTaskId = Id; 
                    ptp.ProductId = Convert.ToInt32(lbi.Value); 
                    ptp.ProductionTaskProductId = -1; 
                    list.Add(ptp); 
                } 
     
                if (list.Count > 0) 
                { 
                    if (e.SourceListBox.TransferToID == "rlbProductsInTask"
                    { 
                        //insert to linking table 
                        InsertList(list); 
                    } 
                    else 
                    { 
                        //delete from linking table 
                        DeleteList(list); 
                    } 
                } 
            } 




Back to Top
UI for ASP.NET Ajax is Ready for VS 2017