【问题标题】:How to clear rad listbox items from client side如何从客户端清除 rad 列表框项目
【发布时间】:2019-03-14 03:16:06
【问题描述】:

我有一个 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】:

    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

    【讨论】:

    • 感谢您的回答,我将其标记为答案,但这也可以正常工作。 var listBox = $find('&lt;%=RadListBox1.ClientID%&gt;'); var items = listBox.get_items(); items.clear();
    猜你喜欢
    • 1970-01-01
    • 2021-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多