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)

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish