Add Item to Bound DropDownList in Code

Posted by David Wier on 05/17/10 | Tips and Tricks

To add an item to the top of a DropDownList at any time, here's the code:
MyDDL.items.insert(0,"WhateverYouWantHERE")

The '0' shows that it needs to insert the item at the top position of the DropDownList item collection. The second part, "WhateverYouWantHERE" is the actual text you want displayed. You could also use this to put a blank item at the top:
MyDDL.items.insert(0,"")

or to specify both value and text:
Dim liItem as ListItem=New ListItem("text", "value")
MyDDL.Items.Insert(0, liItem)





























0 Comments

COMMENTS

Name:
URL:
Comment:

Comments are disabled for this article.