Results 1 to 2 of 2

Thread: Frustrating dropdownlist problem!!

  1. #1

    Thread Starter
    Hyperactive Member greg_quinn's Avatar
    Join Date
    Nov 2002
    Location
    South Africa
    Posts
    366

    Angry Frustrating dropdownlist problem!!

    I am rendering a dropdownlist to a page dynamically in Page_INIT... i.e

    Code:
    Dim typeDropDown As New DropDownList
    
    typeDropDown.ID = "typeDropDown1"
    typeDropDown.DataValueField = "ItemID"
    typeDropDown.DataTextField = "ItemName"
    
    Page.Controls.Add(typeDropDown)
    I then bind my data to the dropdownlist...

    Code:
    PopulateDropdown(typeDropDown, objDataReader("datatable").ToString())
    Now in Page_Load(), I need to set the selected item in the dropdown from the database.

    But setting it manually, using

    Code:
    Dim typeDropDown As New DropDownList
    
    typeDropDown = Page.FindControl("typeDropDown1")
    typeDropDown.Items.FindByText("Choice 2").Selected = True
    Gives me the error...

    A dropdownlist cannot have multiple items selected!!!

    Now why is this happening? I am only setting the selected item the first time in Page_Load(), there are no postbacks or anything on the page. This doesn't make any sense to me. Please help!!!
    He who has conquered himself, is far greater than he who has conquered a thousand men... - The Buddha

  2. #2

    Thread Starter
    Hyperactive Member greg_quinn's Avatar
    Join Date
    Nov 2002
    Location
    South Africa
    Posts
    366

    Talking Re: Frustrating dropdownlist problem!!

    Ok, this is fixed, quite strange fix though.

    Instead of binding to the dropdown in Page_Init, (as I have always done), I moved the binding to Page_Load() in the same routine where the listitem is selected.
    He who has conquered himself, is far greater than he who has conquered a thousand men... - The Buddha

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width