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

don't allow transfer on certain item

4 Answers 184 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
appdev
Top achievements
Rank 1
appdev asked on 14 Jul 2009, 01:43 AM
can i disable transfer function on certain item? in my case, if the item has value of 0 or "" or the item is enabled = false then do not allow transfering on that item. can i do that on client side? please help. thanks.

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 14 Jul 2009, 06:00 AM
Hi Duy,

Try the following clientside code for allowing transferring of items based on condition.

ASPX:
 
<telerik:RadListBox runat="server" ID="RadListBoxSource" Height="200px" Width="230px" 
    OnClientTransferring="OnClientTransferring" AllowTransfer="True" TransferToID="RadListBoxDestination"
    <Items> 
        <telerik:RadListBoxItem Text="Argentina" runat="server"   Value="0"/> 
        <telerik:RadListBoxItem Text="Australia" runat="server" Value="0" /> 
        <telerik:RadListBoxItem Text="Brazil" runat="server" Enabled="false" /> 
        <telerik:RadListBoxItem Text="Canada" runat="server" /> 
    </Items> 
</telerik:RadListBox> 
<telerik:RadListBox runat="server" ID="RadListBoxDestination" Height="200px" Width="200px"
</telerik:RadListBox> 

JavaScript:
 
<script type="text/javascript"
function OnClientTransferring(sender, args) 
    if(args.get_items().length >0) 
    { 
        for(var i=0; i< args.get_items().length; i++ ) 
        { 
            var text = args.get_items()[i].get_value(); 
            if(text == '0' || text == '' || !args.get_items()[i].get_isEnabled()) 
            { 
                args.set_cancel(true); 
                alert('The item cannot be transfered !'); 
            } 
        } 
    } 
</script> 
Note: I suggest you to set value as "0" rather than setting as null, because when I tried I am getting the value same as what I provide for text (when I set value as "").

-Shinu.
0
appdev
Top achievements
Rank 1
answered on 14 Jul 2009, 08:10 PM
well, that works great. thank you for that.

But if you hit transfer all button, nothing will get transfer. so how do you prevent that to happen and allow everything transfer over except for header?
0
Accepted
Veselin Vasilev
Telerik team
answered on 15 Jul 2009, 08:58 AM
Hi Duy,

Here is another idea - cancel the OnClientTransferring event and manually transfer the appropriate items using the transferItem method of RadListBox:

function onClientTransferring(sender, e) {debugger 
    //cancel the event 
    e.set_cancel(true); 
 
    //manually transfer the appropriate items 
    var items = e.get_items(); 
    for (var i = 0; i < items.length; i++) { 
        var item = items[i]; 
        if (item.get_text() != "0" && item.get_text() != "") { 
            sender.transferItem(item, e.get_sourceListBox(), e.get_destinationListBox()); 
        } 
    } 

I hope this helps.

Best wishes,
Veselin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Arpit
Top achievements
Rank 1
answered on 23 Dec 2010, 07:25 PM
 
Tags
ListBox
Asked by
appdev
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
appdev
Top achievements
Rank 1
Veselin Vasilev
Telerik team
Arpit
Top achievements
Rank 1
Share this question
or