0

在此处输入图像描述

如何使用服务器端的代码或客户端的 javascript 从左到右防止特定项目。

例如:如果用户想将“阿根廷”从左向右移动,我想阻止并显示一条警告消息说“不可能”

       RoleSelectedListBox = new RadListBox();
        RoleSelectedListBox.ID = "RoleSelectedListBox";
        RoleSelectedListBox.TabIndex = 1;
        //RoleSelectedListBox.CssClass = "RoleSelectedListBoxStyle";
        RoleSelectedListBox.SelectionMode = ListBoxSelectionMode.Multiple;
        RoleSelectedListBox.AllowTransfer = true;
        RoleSelectedListBox.TransferToID = "RoleAvailableListBox";
        RoleSelectedListBox.Skin = "FuzeCustom";
        RoleSelectedListBox.EnableEmbeddedSkins = false;
        RoleSelectedListBox.EnableDragAndDrop = true;
        RoleSelectedListBox.EnableMarkMatches = true;
        RoleSelectedListBox.Sort = RadListBoxSort.Ascending;
        RoleSelectedListBox.SortItems(); 
4

1 回答 1

0

请尝试使用以下代码片段。

客户端

JS

<script type="text/javascript">
    function ClientTransferring(sender, args) {

        if (args.get_items().length > 0) {
            for (var i = 0; i < args.get_items().length; i++) {
                if (args.get_items()[i]._element.textContent == "Argentina") {
                    args.set_cancel(true);
                    alert("your message comes here");
                }
            }
        }
    }
</script>

ASPX

<telerik:RadListBox runat="server" ID="RadListBoxSource" Height="200px" Width="230px"
    AllowTransfer="true" TransferToID="RadListBoxDestination" OnClientTransferring="ClientTransferring">
    <Items>
        <telerik:RadListBoxItem Text="Argentina"></telerik:RadListBoxItem>
        <telerik:RadListBoxItem Text="Australia"></telerik:RadListBoxItem>
        <telerik:RadListBoxItem Text="Brazil"></telerik:RadListBoxItem>
        <telerik:RadListBoxItem Text="Canada"></telerik:RadListBoxItem>
        <telerik:RadListBoxItem Text="Chile"></telerik:RadListBoxItem>
        <telerik:RadListBoxItem Text="China"></telerik:RadListBoxItem>
        <telerik:RadListBoxItem Text="Egypt"></telerik:RadListBoxItem>
        <telerik:RadListBoxItem Text="England"></telerik:RadListBoxItem>
        <telerik:RadListBoxItem Text="France"></telerik:RadListBoxItem>
        <telerik:RadListBoxItem Text="Germany"></telerik:RadListBoxItem>
        <telerik:RadListBoxItem Text="India"></telerik:RadListBoxItem>
        <telerik:RadListBoxItem Text="Indonesia"></telerik:RadListBoxItem>
        <telerik:RadListBoxItem Text="Kenya"></telerik:RadListBoxItem>
        <telerik:RadListBoxItem Text="Mexico"></telerik:RadListBoxItem>
        <telerik:RadListBoxItem Text="New Zealand"></telerik:RadListBoxItem>
        <telerik:RadListBoxItem Text="South Africa"></telerik:RadListBoxItem>
        <telerik:RadListBoxItem Text="USA"></telerik:RadListBoxItem>
    </Items>
</telerik:RadListBox>
<telerik:RadListBox runat="server" ID="RadListBoxDestination" Height="200px" Width="200px">
</telerik:RadListBox>

服务器端

ASPX

<telerik:RadListBox runat="server" ID="RadListBoxSource" Height="200px" Width="230px"
    AllowTransfer="true" TransferToID="RadListBoxDestination" AutoPostBackOnTransfer="true"
        OnTransferring="RadListBoxSource_Transferring">
    <Items>
        <telerik:RadListBoxItem Text="Argentina"></telerik:RadListBoxItem>
        <telerik:RadListBoxItem Text="Australia"></telerik:RadListBoxItem>
        <telerik:RadListBoxItem Text="Brazil"></telerik:RadListBoxItem>
        <telerik:RadListBoxItem Text="Canada"></telerik:RadListBoxItem>
        <telerik:RadListBoxItem Text="Chile"></telerik:RadListBoxItem>
        <telerik:RadListBoxItem Text="China"></telerik:RadListBoxItem>
        <telerik:RadListBoxItem Text="Egypt"></telerik:RadListBoxItem>
        <telerik:RadListBoxItem Text="England"></telerik:RadListBoxItem>
        <telerik:RadListBoxItem Text="France"></telerik:RadListBoxItem>
        <telerik:RadListBoxItem Text="Germany"></telerik:RadListBoxItem>
        <telerik:RadListBoxItem Text="India"></telerik:RadListBoxItem>
        <telerik:RadListBoxItem Text="Indonesia"></telerik:RadListBoxItem>
        <telerik:RadListBoxItem Text="Kenya"></telerik:RadListBoxItem>
        <telerik:RadListBoxItem Text="Mexico"></telerik:RadListBoxItem>
        <telerik:RadListBoxItem Text="New Zealand"></telerik:RadListBoxItem>
        <telerik:RadListBoxItem Text="South Africa"></telerik:RadListBoxItem>
        <telerik:RadListBoxItem Text="USA"></telerik:RadListBoxItem>
    </Items>
</telerik:RadListBox>
<telerik:RadListBox runat="server" ID="RadListBoxDestination" Height="200px" Width="200px">
</telerik:RadListBox>

ASPX.CS

protected void RadListBoxSource_Transferring(object sender, RadListBoxTransferringEventArgs e)
{
    if (e.Items.Count > 0)
    {
        foreach (RadListBoxItem item in e.Items)
        {
            if (item.Text == "Argentina")
            {
                e.Cancel = true;
                //show your message from here
            }
        }
    }
}
于 2014-09-22T20:01:38.357 回答