Either disable view state for the control or walk the collection of items
and set "selected" to false for all but the one you want.  The control is
holding on to the selected setting from the last post and then you are
probably setting another item to be selected.

HTH,
Matt

Matt Milner
BORN
[EMAIL PROTECTED]


-----Original Message-----
From: Kevin Burton
To: [EMAIL PROTECTED]
Sent: 5/29/02 5:05 PM
Subject: [DOTNET] ListBox error in ASP.NET

I have a ListBox that I only want to have a single item selected at a
time
and when that item is selected I want it to be copied into another
ListBox
(this is an example in ASP.NET Unleashed p. 224 and 225). The first
selection works just fine but the second selection gives me the
following
error. It seems that the error is getting thrown before the first
selected
item is unselected. Any ideas as to a work around?

Kevin

A ListBox cannot have multiple items selected when the SelectionMode is
Single.

Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Web.HttpException: A ListBox cannot have
multiple
items selected when the SelectionMode is Single.

Source Error:

An unhandled exception was generated during the execution of the current
web
request. Information regarding the origin and location of the exception
can
be identified using the exception stack trace below.

Stack Trace:


[HttpException (0x80004005): A ListBox cannot have multiple items
selected
when the SelectionMode is Single.]
   System.Web.UI.WebControls.ListBox.RenderContents(HtmlTextWriter
writer)
+343
   System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer)
+29
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +72
   System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter
writer)
+44
   System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output)
+397
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +72
   System.Web.UI.Control.Render(HtmlTextWriter writer) +7
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
   System.Web.UI.Page.ProcessRequestMain() +1900

You can read messages from the DOTNET archive, unsubscribe from DOTNET,
or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to