Wednesday, March 21, 2012

Populating a DropDownList

Is there a way to manually insert rows into a dropdownlist.
I nneed to insert a value and a display text.Yes, you may use " DropDownList.Items.Add" or "Items.Insert".
How do you add a value and a display text?
ddlb.Add("50","New York") does not work. It appears to only take one argument.
OK. Do it like this:

Dim newItem As ListItem = New ListItem("New York", "50")
ddlb.Items.Add(newItem)

This will add a new item at bottom of your DDL, if you want add it in a certain palce, you amy do like this:

ddlb.Items.Insert(0,newItem)

This will add it in the very top.

0 comments:

Post a Comment