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

OnClientTransfering Validate item value exist in destination ListBox

3 Answers 119 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Winarsanti Laksmitarani
Top achievements
Rank 1
Winarsanti Laksmitarani asked on 02 Sep 2013, 04:49 PM
I need to check item value when transfering if its already exist in destination listbox.
I came up with this code, but it always failed to get destination items length.
function validateItemTransfer(sender, args) {
                        debugger;
                        var items = args.get_items();
                        for (var i = 0; i < items.length; i++) {
                            var item = items[i];
 
                            var destinationItems = args.get_destinationListBox().get_items();
                            for (var j = 0; j < destinationItems.length; j++) {
                                var destinationItem = destinationItems[j];
                                if (item.get_value() == destinationItem.get_value()) {
                                    args.set_cancel(true);
                                }
                            }
                        }
                    }

Pls help,

Thanks..

3 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 03 Sep 2013, 05:17 AM
Hi Winarsanti Laksmitarani,

To check for duplicate items set the AllowTransferDuplicates property of the RadListBox to true. Please have a look at the following Javascript to get the destination RadListBox length.

ASPX:
<telerik:RadListBox ID="RadListBox1" runat="server" TransferToID="RadListBox2" AllowTransfer="true"
    TransferMode="Copy" SelectionMode="Multiple" OnClientTransferred="OnClientTransferred1">
    <Items>
        <telerik:RadListBoxItem runat="server" Text="Item1" Value="1" />
        <telerik:RadListBoxItem runat="server" Text="Item2" Value="2" />
        <telerik:RadListBoxItem runat="server" Text="Item3" Value="1" />
        <telerik:RadListBoxItem runat="server" Text="Item4" Value="2" />
        <telerik:RadListBoxItem runat="server" Text="Item5" Value="3" />
    </Items>
</telerik:RadListBox>
<telerik:RadListBox ID="RadListBox2" runat="server">
</telerik:RadListBox>

JavaScript:
<script type="text/javascript">
    function OnClientTransferred1(sender, args) {
        var destinationListbox = $find('<%=RadListBox2.ClientID %>');
        var count = destinationListbox.get_items().get_count();
        alert("Destination listbox count :" + count);
    }
</script>

Thanks,
Shinu.
0
Winarsanti Laksmitarani
Top achievements
Rank 1
answered on 04 Sep 2013, 02:06 AM
Hi Shinu,

Thanks for your solution, i though i could use .length function to get the size, i don't know it should use get_count() method instead.
Btw how do you know all API inside getDestinationListBox() ?


Best regards
0
Shinu
Top achievements
Rank 2
answered on 04 Sep 2013, 04:25 AM
Hi Winarsanti Laksmitarani,

You will get the Client Side API for RadListBox from this documentation.

Thanks,
Shinu.
Tags
ListBox
Asked by
Winarsanti Laksmitarani
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Winarsanti Laksmitarani
Top achievements
Rank 1
Share this question
or