I am rendering a dropdownlist to a page dynamically in Page_INIT... i.e
I then bind my data to the dropdownlist...Code:Dim typeDropDown As New DropDownList typeDropDown.ID = "typeDropDown1" typeDropDown.DataValueField = "ItemID" typeDropDown.DataTextField = "ItemName" Page.Controls.Add(typeDropDown)
Now in Page_Load(), I need to set the selected item in the dropdown from the database.Code:PopulateDropdown(typeDropDown, objDataReader("datatable").ToString())
But setting it manually, using
Gives me the error...Code:Dim typeDropDown As New DropDownList typeDropDown = Page.FindControl("typeDropDown1") typeDropDown.Items.FindByText("Choice 2").Selected = True
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!!!




Reply With Quote