Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
95
Single select drop down ends up with multiple selections?
posted

I have a user account page where users can be created, or edited.  On the page are several webdropdown controls.

<ig:WebDropDown ID="ddlCityId" runat="server" Width="200px" EnableMultipleSelection="false" />

Essentially, the process of the page is:

Page loads, if not post back, it binds the drop downs, and adds an empty option up top (this works fine).

If Not Page.IsPostBack Then

ddlCityId.DataSource = WebTool.GetCities()
        ddlCityId.TextField = "city_name"
        ddlCityId.ValueField = "city_id"
        ddlCityId.DataBind()
        ddlCityId.Items.Insert(0, New Infragistics.Web.UI.ListControls.DropDownItem())

End If

If an existing user is selected, the data for that user is loaded in prerender, and the form is filled out.  I set currentvalue and selectedvalue for each drop down... (this also seems to work fine.)

LoadUser()

If user.CityId > 0 Then
    ddlCityId.SelectedValue = user.CityId
    'ddlCityId.Items.FindItemByValue(user.CityId).Selected = True
    ddlCityId.CurrentValue = user.CityName

End If

 

I was trying different ways of selecting the item... the remarked line worked fine, but browsing the forums, it seems the first method is preferred (it's what I originally had done, but didnt' understand I needed to set the current value to have it show up correctly as well, so I was trying different things).

On submit, someone could pick a new city, in which case I would just save the newly selected one:

user.CityId = ddlCityId.SelectedValue

Here's where the problem occurs... when I look at that, I end up with TWO selecteditems, so if the newly selected item is lower on the list than the previous item, it just saves the old value since that is the one at index 0 in the selecteditems collection.  This seems totally backwards to me, like the default behavior is what I would expect the one off method to be... so to be totally clear, if I look at the control on submission, I get values for both of these:

'Dim str As String = ddlCityId.SelectedItems(0).Value
'Dim str2 As String = ddlCityId.SelectedItems(1).Value

 

What do I need to do differently?  Thanks!

Parents
No Data
Reply Children