Filling DropDownList Box

saidev

Active member
Joined
Dec 22, 2005
Messages
27
Programming Experience
1-3
Guys,

Can you guys let me know how to fill the dropdown list box programatically with code in ASP.NET(VB.NET)

Thanks,
 
VB.NET:
[SIZE=2]
DropDownList1.Items.Add("Select ...")
DropDownList1.Items.Add("Something 1")
DropDownList1.Items.Add("Something 2")
DropDownList1.Items.Add("Something 3")
[/SIZE]


VB.NET:
[SIZE=2][COLOR=#0000ff]With[/COLOR][/SIZE][SIZE=2] DropDownList1
   .Items(0).Selected = [/SIZE][SIZE=2][COLOR=#0000ff]True
[/COLOR][/SIZE][SIZE=2] .Items(0).Value = ""[/SIZE]
[SIZE=2] [COLOR=darkgreen]'also for the other items[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]With[/COLOR][/SIZE]

or
VB.NET:
[COLOR=blue]For[/COLOR] i [COLOR=blue]as[/COLOR] integer = 0 [COLOR=blue]to[/COLOR] 3
    DropDownList1.Items.Add("Something " & i)
[COLOR=blue]Next[/COLOR]


Regards ;)

edit: also notice that you can populate ddlist through its DataSource property
 
Last edited:
Back
Top