I am trying to add each item from dropdownlist to label. Any guesses why it won’t work. Thanks for your answers.
Dim labels(2) As Label
Public Sub AddItemsFromDropdownlistToLabel()
DefineLabels()
'Add Items From Dropdownlist1 to three lables
For Each item As Object In DropDownList1.Items
If LabelCount < 3 AndAlso LabelCount > 0 Then
labels(LabelCount).Text = item.ToString
End If
Next
End Sub
Public Sub DefineLabels()
labels(0) = label1
labels(1) = label2
labels(2) = label3
End Sub
Couple of problems
1: Since you’re checking
LabelCount>0labels(0)will never be populated.2: You’ve not got anything incrementing for each item in the loop to advance the population of the labels array.
3: Each
itemin your drop down is an instance ofListItem. To get a anything useful out of that, you’re best to use eitheritem.Textoritem.Value.