This is a migrated thread and some comments may be shown as answers.

Which Transfer button has been clicked

5 Answers 119 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
NMQA
Top achievements
Rank 2
NMQA asked on 23 Nov 2011, 01:12 PM
Hi Telerik,

This looks to be a fairly straight forward thing, be I cannot seem to detect which Arrow (To Right or To Left) have been clicked on the OnTransferred event (server-side).

Here is some sample codes:
<telerik:RadListBox runat="server" ID="listBoxSourceOS" Height="200px" Width="230px"                                                    OnDropped="listBoxSourceOS_OnDropped" ButtonSettings-ShowTransferAll="false"                                                    EnableDragAndDrop="true" AutoPostBackOnTransfer="true" OnTransferred="ListBoxSourceOS_OnTransferred"                                                    AllowTransfer="true" TransferToID="listBoxDestinationOS">
</telerik:RadListBox>
 
<telerik:RadListBox TransferToID="listBoxSourceOS" Height="200px" ID="listBoxDestinationOS" AutoPostBackOnTransfer="true" AllowTransfer="true" runat="server" Width="230px" />

protected void ListBoxSourceOS_OnTransferred(object sender, RadListBoxTransferredEventArgs e)
        {
            //((Telerik.Web.UI.RadListBoxItem[])(e.Items))[0].Value
            if (e.Items != null)
            {
                //Insert new item
                //Refresh List
            }
        }


Based on the type of transfer, a delete or insert operation will the be carried out into the database, all in the code-behind page(server side)

Furthermore, this same scenario will be applied for the OnDropped events.

Thanks

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 23 Nov 2011, 01:49 PM
Hello,

The OnTransferred event fires whenever there is a drag and drop or transfer between the ListBoxes depending on the direction of transfer.

-Shinu.
0
NMQA
Top achievements
Rank 2
answered on 23 Nov 2011, 02:10 PM
Hi,

In my case, OnTransferred is being triggered regardless of which Arrow have been pressed. My understanding is to find out the type of the arrow clicked on at this point.. 

Cheers!
0
Accepted
Kevin
Top achievements
Rank 2
answered on 23 Nov 2011, 04:04 PM
Hello NMQA,

You could use this piece of code to determine if a delete or insert operation should be performed:

protected void RadListBox1_Transferred(object sender, RadListBoxTransferredEventArgs e)
    {
        if (e.DestinationListBox != sender)
        {
            // perform delete logic
        }
        else if (e.DestinationListBox == sender)
        {
            // perform insert logic
        }
    }

So if the DestinationListBox is not the sender, it means an item was removed from it. If the sender is the DestinationListBox, it means an item is being added to it.

I hope that helps.
0
NMQA
Top achievements
Rank 2
answered on 23 Nov 2011, 04:38 PM
Thank you Sir! 

Came up with this, which basically is the same thing that you've proposed.

if (e.SourceListBox == listBoxSourceOS)
{
    //Do something
}
else
{
    //Do something
}

Nice one Kevin!
0
Josef Rogovsky
Top achievements
Rank 2
answered on 07 Aug 2015, 07:04 PM

Thanks, All

This thread was helpful.

Tags
ListBox
Asked by
NMQA
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
NMQA
Top achievements
Rank 2
Kevin
Top achievements
Rank 2
Josef Rogovsky
Top achievements
Rank 2
Share this question
or