I am using asp.net and vb.net as code behind. I have dropdown box. It will populate the list of values on page load. I have a data coming from webservice. arrdata consists of web service data.
If IsNothing(arrData(12)) Then
DropDownList_mylist.Items.Add(New ListItem("Choose"))
DropDownList_mylist.SelectedIndex = DropDownList_mylist.Items.IndexOf(DropDownList_mylist.Items.FindByText("Choose"))
Else
DropDownList_mylist.SelectedIndex = DropDownList_mylist.Items.IndexOf(DropDownList_mylist.Items.FindByText(arrData(12)))
End If
The problem is, it is giving the first item. not the correct item.
Use the AppendDataBoundItems property and set it to true if there are existing items in the list already.
Similar question here:
Dropdown list bound to object data source – how to update on a button click