dropdownlist multiple selection error

Joined
Feb 14, 2008
Messages
1
Reaction score
0
I'm receiving the following error:
"Cannot have multiple items selected in a DropDownList."
when my page loads

here is the code in the Page_Load event...

Dim r As Integer = 0
Dim strSvcData() As String
Dim lstItm As ListItem

'i populate the array here - this is working fine

For r = 0 To UBound(strSvcData)
lstItm = New ListItem
lstItm.Text = strSvcData(r)
lstItm.Value = r
lstItm.Selected = False
DropDownList1.Items.Add(lstItm)
Next

DropDownList1.SelectedIndex = -1
'i also used "DropDownList1.ClearSelection()" here but that didn't work either

lstItm = New ListItem
lstItm.Text = "Select"
lstItm.Value = "top"
lstItm.Selected = True
DropDownList1.Items.Add(lstItm)
'also tried here "DropDownList1.Items.Insert(0, lstItm)" with same results


i've tried this with and without explicitly setting the selected property.
i've also tried

DropDownList1.ClearSelection()
DropDownList1.SelectedIndex = 0

there is no error if i remove the line to set the selected index, but the problem is that rather than showing the "Select" item, it shows the first item that is set in the for...next loop...

thanks in advance!
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top