Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: ListItem Question


Message #1 by "charles baldo" <charlesbaldo@h...> on Mon, 04 Mar 2002 18:30:56
Can anyone help me with this problem



I have a dropdown list of states the value is the 2 char state code and the 

text is the state name. When I go from one form to another I want to select 

the state of the previous form.



I am using the following code to do this



  Dim objListItem As ListItem

  Dim objListControl As ListControl

  Dim strState As String



  objListControl = BillingState ' this is the id of the dropdownlist



  strState = "NY"



  objListItem = objListControl.Items.FindByValue(strState)

  objListItem.Selected = True



When I execute this I get this error



System.Web.HttpException: A DropDownList cannot have multiple items selected





I have got this code to work before but the values were numbers any help 

please



Thank You

Chuck



_________________________________________________________________

Join the world?s largest e-mail service with MSN Hotmail. 

http://www.hotmail.com



Message #2 by <zivf@m...> on Tue, 5 Mar 2002 12:18:15 +0200
What you are trying to do is to add a selected item to the selected 

items list. this is only possible to do when selection specification is 

set to "multiple".

What you need to do is ONE of the following:



1. call the ClearSelection() method before setting selection



2. set the selected index property of the list control according to the 

index of the item you want to select. you can find the item's index 

using Items.IndexOf(item) - watch out not to set the VALUE of the item, 

but its INDEX in the list



regards,

Ziv.



-----Original Message-----

From: charles baldo [mailto:charlesbaldo@h...]

Sent: Monday, March 04, 2002 8:31 PM

To: ASP+

Subject: [aspx] ListItem Question





Can anyone help me with this problem



I have a dropdown list of states the value is the 2 char state code and 

the

text is the state name. When I go from one form to another I want to 

select

the state of the previous form.



I am using the following code to do this



  Dim objListItem As ListItem

  Dim objListControl As ListControl

  Dim strState As String



  objListControl =3D BillingState ' this is the id of the dropdownlist



  strState =3D "NY"



  objListItem =3D objListControl.Items.FindByValue(strState)

  objListItem.Selected =3D True



When I execute this I get this error



System.Web.HttpException: A DropDownList cannot have multiple items 

selected





I have got this code to work before but the values were numbers any help 



please



Thank You

Chuck



_________________________________________________________________

Join the world=92s largest e-mail service with MSN Hotmail.

http://www.hotmail.com









  Return to Index