set default value in dynamic drop down

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Garima12
    New Member
    • Mar 2007
    • 58

    set default value in dynamic drop down

    There is dropdown on webpage and I m filling it dynamically at run time. I want to set an item as selecteditem. that item will be decided on the page load based upon value I got from databse.
    I set DataTextField,D ataValueField properties of dropdown.
    Initially I got data printed on label and set dropdown.select edvalue=label1. text
    it was working fine before setting DataValueField.
    after setting DataValueField, it is throwing error "item you are trying to set as selecteditem is not in the list."
    Please tell me some solution.
  • malav123
    New Member
    • Feb 2008
    • 217

    #2
    Hi garima,
    I am not getting exactly what is problem in your application.... so please tell me the problem clearly...

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      Set the SelectedIndex to a value?

      Comment

      • balabaster
        Recognized Expert Contributor
        • Mar 2007
        • 798

        #4
        Originally posted by Plater
        Set the SelectedIndex to a value?
        Plater, I don't think she's asking quite what you think. In the database, she's storing the selected value which you can't set at runtime, only read. So we have to find the index from the value.

        Dim MyValue As Integer = OledbDataReader 1("StoredValue" )
        MyDropList.Sele ctedIndex = MyDropList.Inde xOf(MyDropList. FindByValue(MyV alue))

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          You just described in much better depth what I was trying to get out.
          Sometimes work eats my brain.

          Comment

          • balabaster
            Recognized Expert Contributor
            • Mar 2007
            • 798

            #6
            Originally posted by Plater
            You just described in much better depth what I was trying to get out.
            Sometimes work eats my brain.
            It's odd...I'm at work, stuck in meetings...and I spend more time answering questions on here so that the incessant roundabout conversations don't eat my brain.

            Comment

            Working...