Thursday, March 29, 2012

single value addition to dropdownlist

Hi , I have a dropdownlist and I am adding some values from an array and bind it as you can see below(quickstart tutorial sample)

Dim values as ArrayList= new ArrayList()

values.Add ("IN")
values.Add ("KS")
values.Add ("MD")
values.Add ("MI")
values.Add ("OR")
values.Add ("TN")

DropDown1.DataSource = values
DropDown1.DataBind

But I need to add a new value to dropdownlist after the databinding.How can I add a new record to drpdownlist ? I can set a new array but it seems the hard way of it .Easily an addition can be done but how I dont know ..

Thanks...

DropDown1.Items.Add("Text")

or

DropDown1.Items.Add(New ListItem("text","value"))

and if you want to insert it on top

DropDown1.Items.Insert(0,New ListItem("text","value"))


dropdownid.Items.Add()

As parameters you can give either a string or a ListItem.

-Vincent

ps, If you want to add an item in a specific spot instead of at the end then use Items.Insert()

joteke:

and if you want to insert it on top

DropDown1.Items.Insert(0,New ListItem("text","value"))

That was exactly thing that I wanted.

Thanks for the reply..

0 comments:

Post a Comment