Tuesday, May 22, 2007

Add Item to Bound DropDownList

Add Item to Bound DropDownList
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)

No comments: