请尝试使用以下代码片段。
客户端
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
}
}
}
}