How To Clear An ASP.NET Listbox With Javascript?
I'm trying to clear all of the items in an ASP.NET listbox via javascript, but sadly document.getElementById('<%= lstNames.clientID %>').items.clear; does not work. Any idea
Solution 1:
Use jquery document.getElementById("<%= lstNames.clientID %>").empty()
or
document.getElementById("<%= lstNames.clientID %>").options.length = 0;
Solution 2:
Use:
document.getElementById("<%= lstNames.clientID %>").selectedIndex = -1; // will throw error on next if there are selected items
document.getElementById("<%= lstNames.clientID %>").options.length = 0;
or
document.getElementById("<%= lstNames.clientID %>").innerHTML = "";
Post a Comment for "How To Clear An ASP.NET Listbox With Javascript?"