Portal Error - A DropDownList cannot have multiple items selected.

T

Tom Bray

Ok I am baffled I can not figure out this problem. I am getting the
following error:

Portal Error - A DropDownList cannot have multiple items selected.

Error information
Name Value
Message A DropDownList cannot have multiple items selected.
Source System.Web
TargetSite Void RenderContents(System.Web.UI.HtmlTextWriter)
StackTrace at
System.Web.UI.WebControls.DropDownList.RenderContents(HtmlTextWriter writer)
at System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) at
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) at
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) at
System.Web.UI.Control.Render(HtmlTextWriter writer) at
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) at
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) at
System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter
writer) at System.Web.UI.Control.RenderControl(HtmlTextWriter writer) at
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) at
System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer) at
System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output) at
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) at
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) at
System.Web.UI.Control.Render(HtmlTextWriter writer) at
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) at
System.Web.UI.Page.ProcessRequestMain()


Also, I do you use the clearselection() method before loading any drop downs
so please do not offer that as a solution. Also, how come I don't get the
line number of the control that is having the problem? I am running IIS 5.0
and this using 1.1 framework.

Please help this won't go away ;).

--Tom
 
J

JeffSchumacher

I've had the same problem in different variations. Sometimes it's bee
due to databinding to a field with a NULL value. Other times ther
seems to be a problem with the RequiredFieldValidator and the dropdow
list control. I have one page in particular that gives this sam
exception after I use the Validate method on th
RequiredFieldValidator. Strangely enough, it seems to reset all of th
dropdown list controls on my page to have a selectedindex of 0, plus th
selectedindex that was previously set. I've been able to trap this b
adding an exception handler in the Render page override
 
J

JeffSchumacher

Turns out that what was causing my problem did have something to do wit
the RequiredFieldValidator control a ListItem object I used to add
"Please Select" option to each of four dropdowns. The code looke
something like this:

Dim tempItem As New System.Web.UI.WebControls.ListItem
tempItem.Text = "Please select..."
tempItem.Value = ""
tempItem.Selected = False
Me.ddlTest1.Items.Insert(0, tempItem)
Me.ddlTest2.Items.Insert(0, tempItem)
Me.ddlTest3.Items.Insert(0, tempItem)
Me.ddlTest4.Items.Insert(0, tempItem)

To correct the problem, I used separate ListItem variables for eac
control:

Dim tempItem As New System.Web.UI.WebControls.ListItem
tempItem.Text = "Please select..."
tempItem.Value = ""
tempItem.Selected = False
Me.ddlTest1.Items.Insert(0, tempItem)

Dim tempItem2 As New System.Web.UI.WebControls.ListItem
tempItem2.Text = "Please select..."
tempItem2.Value = ""
tempItem2.Selected = False
Me.ddlTest2.Items.Insert(0, tempItem2)

Dim tempItem3 As New System.Web.UI.WebControls.ListItem
tempItem3.Text = "Please select..."
tempItem3.Value = ""
tempItem3.Selected = False
Me.ddlTest3.Items.Insert(0, tempItem3)

Dim tempItem4 As New System.Web.UI.WebControls.ListItem
tempItem4.Text = "Please select..."
tempItem4.Value = ""
tempItem4.Selected = False
Me.ddlTest4.Items.Insert(0, tempItem4)

My guess is the the Validate function somehow uses a reference to th
original tempItem variable I had defined, and there were 4 control
referencing that variable. Go figure
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top