Clearing a DropDownList

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
Is there a way to clear a DropDownList from code behind, something similar
to myDropDownList.length=0 on the client?

Thanks.
 
Hi,

This should work:

document.getElementById('dropdownlistname').options.length = 0;

Good luck! Ken.
 
Vi said:
Hi,
Is there a way to clear a DropDownList from code behind, something similar
to myDropDownList.length=0 on the client?

The DropDownList has an Items property with methods for adding and
removing ListItems. There's Clear(), which will remove *all* items
(DDLID.Items.Clear()), and there's also methods like Add(), Insert(),
Remove(), and RemoveAt().

hth

--

Scott Mitchell
(e-mail address removed)
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
 
Back
Top