|
-
May 15th, 2005, 11:21 AM
#1
Thread Starter
Hyperactive Member
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
-
May 15th, 2005, 11:27 AM
#2
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|