I am working with an Unbound DropDownList that is binding from sql table.
Having done the same process with ListBoxes, I am becoming familiar with the necessary elements.
DataTextField, DataValueField, DataMember, AppendDataBound are all set correct.
I am running into an issue, where running one style of code works 50% correct, the other style works 50% correct, yet I need both functions.
The goal is to have the selected item from within the DropDownList (upon user clicking button) be dynamically used elsewhere.
The DataBind is working correctly, but after each "button clicked event", the binded data was doubling, tripling, quad. etc....
I had run into this problem prior with a ListBox and corrected easily by doing: ListBox.Items.Clear()
OPTION 1: Presently, if I use the code with the DropDownList.Tems.Clear(), the selected item doesn't matter. It is grabbing the first index (which is my problem), but does remove duplicate data from databind by clearing items correctly.
OPTION 2: If I remove the DropDownList.Tems.Clear(), it does grab the selected items text correctly, but binds the data double, triple, quad. etc.... upon button clicks.
It seems like the DropDownList should work the same as the ListBoxes, but there must be something I am overlooking.
I have also tried using myParam method in both Selected.Text & Selected.Value format, but it doesn't seem to need this, since OPTION 2 works without:
Dim myParam As SqlParameter = New SqlParameter("@myParam", SqlDbType.Nvarchar, 100)
myParam.Value = DropDownList.SelectedItem.Text
What do I need to do, so OPTION 1 works correctly and doesn't select the first index of the DropDownList?
or
What do I need to do, so OPTION 2 works correctly and doesn't include duplicate databind data?
Feedback Appreciated,
-machina12