ARPRINCE
Apr 23rd, 2004, 03:32 PM
How do you add text and Value to a dropdown programatically?
Right now I use the binding method with no problems.
DropDownList1.DataTextField = "Name"
DropDownList1.DataValueField = "CustomerID"
DropDownList1.DataSource = SQLQuery()
DropDownList1.DataBind()
However I have a need to do it manually on some of my dropdown web controls.
I can add items into the collection but the TEXT and VALUE are both the same when it should have been (ex Finance, 001).
With DropDownList2
.Items.Add("Finance")
.Items.Add("Design")
.Items.Add("Management")
End With
**** DATA ****
Dept Code
------- ------
FINANCE 001
DESIGN 002
MANAGEMENT 003
TIF
Right now I use the binding method with no problems.
DropDownList1.DataTextField = "Name"
DropDownList1.DataValueField = "CustomerID"
DropDownList1.DataSource = SQLQuery()
DropDownList1.DataBind()
However I have a need to do it manually on some of my dropdown web controls.
I can add items into the collection but the TEXT and VALUE are both the same when it should have been (ex Finance, 001).
With DropDownList2
.Items.Add("Finance")
.Items.Add("Design")
.Items.Add("Management")
End With
**** DATA ****
Dept Code
------- ------
FINANCE 001
DESIGN 002
MANAGEMENT 003
TIF