如何从客户端清除rad列表框项目

问题描述 投票:0回答:1

我有一个radlistbox我想清除radlistbox项目。我曾尝试过这段代码但没有按预期工作。有人可以告诉我如何才能做到这一点。

谢谢。

 <telerik:RadListBox RenderMode="Lightweight" runat="server" AllowReorder="True" AllowDelete="true" ID="RadListBox1" Height="200px" Width="230px" AutoPostBack="false" ButtonSettings-AreaWidth="35px">
      <ButtonSettings Position="Right" AreaWidth="35px"></ButtonSettings>
 </telerik:RadListBox>

脚本:

function ClearListbox()
{
    var listBox = $find('<%=RadListBox1.ClientID%>');
    listBox.trackChanges();
    listBox.clearSelection();
    listBox.commitChanges();

}
javascript telerik
1个回答
0
投票

clearSelection方法只删除所选项目中的突出显示。

您应该使用get_items()。remove或removeAt方法来成功:

var lb = $find("ctl00_ContentPlaceholder1_RadListBoxSource");
var item = lb.get_selectedItem();
lb.trackChanges();
lb.get_items().remove(item);
lb.commitChanges();

您还需要一个选择才能删除所选项目。

有关https://docs.telerik.com/devtools/aspnet-ajax/controls/listbox/radlistbox-items/working-at-client-side#removing-items的更多信息,请查看此文章

© www.soinside.com 2019 - 2024. All rights reserved.