Setting DropDownList selectedItem from database values

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve

    #1

    Setting DropDownList selectedItem from database values

    I'm loading a dropdownlist control from values in a
    database.... after I load the drop down, I need to set
    the selecteditem to another database value... when I do
    this the drop down has an additional value added to the 0
    position rather than setting the proper value.
  • Billy Jacobs

    #2
    Setting DropDownList selectedItem from database values

    You need to set the selected SelectedIndex property. A way
    to do this if you don't know which item it is at design
    time is the following:

    'If your item is a string object.
    dim tmpListItem as System.Web.UI.W ebControls.List item
    tmpListItem = ddlMyDropDownLi st.FindByText(" StringValue")
    'Make sure it found what you were looking for.
    if not tmpListItem is Nothing then
    ddlMyDropDownLi st.SelectedInde x = _
    tmpListItem.Ite ms.IndexOf(tmpL istItem)
    end if

    Hope this helps.[color=blue]
    >-----Original Message-----
    >I'm loading a dropdownlist control from values in a
    >database.... after I load the drop down, I need to set
    >the selecteditem to another database value... when I do
    >this the drop down has an additional value added to the 0
    >position rather than setting the proper value.
    >.
    >[/color]

    Comment

    Working...