Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error converting string to int

Status
Not open for further replies.

James1981

Programmer
Nov 2, 2002
76
US
Hi,

I'm trying to convert the value of a selected item in a dropdown list from a string to an integer. All the values are numbers but i get errors when trying to convert them into int data types.

I have tried the following code:

(int)listCountry.SelectedItem.Value

the compiler raises an error saying that it cannot convert string to int.

I have also tried:

Convert.ToInt32(listCountry.Selecteditem.Value)

but this returns an unhandled error message at runtime.

I need the value in an Int type... Any ideas?

Cheers, James.
 
Convert.ToInt32 is the method you need... what error do you refer to when you say:

an unhandled error message at runtime

What exactly does it tell you?
penny1.gif
penny1.gif

The answer to getting answered -- faq855-2992
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top