【问题标题】:RadListBox: How to disable moving of particular itemRadListBox:如何禁用特定项目的移动
【发布时间】:2014-09-22 19:05:39
【问题描述】:

如何在服务器端使用代码或在客户端使用 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(); 

【问题讨论】:

  • 如何将数据绑定到 RadListBox?

标签: telerik listboxitem rad-controls radlistbox


【解决方案1】:

请尝试以下代码 sn-p。

客户端

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
            }
        }
    }
}

【讨论】:

  • 这里我们使用以下方法使用文本识别项目:'if (args.get_items()[i]._element.textContent == "Argentina")' 如果我想使用我,那我们怎么办呢??
  • 我在这里面临的另一个问题是,我只想停止从左到右传输项目,但是即使我试图从右到左传输项目,事件也会被触发...... ..关于如何解决这个问题的任何想法??
  • @user3792804.... 我知道这已经被问过了一段时间,但 e 还包含 e.DestinationListBox 和 e.SourceListBox。所以你可以做一个 If e.SourceListBox = LeftHandListBox 然后做你的转移 else e.cancel
猜你喜欢
  • 2013-01-15
  • 2011-05-22
  • 1970-01-01
  • 2022-12-16
  • 2015-04-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多