简体   繁体   中英

Removing Items from Telerik Drop down list using jQuery

I know how to add items to a telerik ddl using jquery, but how do I remove values?

Thanks in advance

Here is a demo of RadComboBox with Add/Remove/Disable Items ...

http://demos.telerik.com/aspnet-ajax/combobox/examples/programming/addremovedisableitemsclientside/defaultcs.aspx

Basically - you need to first get combo box itself. Here is the code:

var combo = $find("<%= RadComboBox1.ClientID %>");

Lets assume you want to remove the currently selected item in the combo box. You will need to first grab the item like below:

var comboItem = combo.get_selectedItem();

Now to remove the above item from the combo box, we first need to get the items collection and then call the remove method on the collection by passing the item we want to remove. Here is the code snippet for the same:

if(comboItem)
        { 
            combo.trackChanges();
            combo.get_items().remove(comboItem);
            combo.commitChanges();
        }

Here is another example of removing an item from the combobox - this time we search the item by its name:

var combo = $find("<%= RadComboBox1.ClientID %>");
var items = combo.get_items();
var comboItem = combo.findItemByText("Paris");
combo.trackChanges();
items.remove(comboItem); 
combo.commitChanges();

Here is the documentation for the client side API of ComboBox (disclaimer: I'm part of Telerik):

http://www.telerik.com/help/aspnet-ajax/combobox-client-side-radcomboboxitemcollection.html

this will remove all items from dropdown .

var combo2 = $find('<%= drp_Year.ClientID%>');
combo2.get_items().clear()

https://a2zcode.com/Removing-Items-from-Telerik-Drop-down-list-using-jQuery

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM