Click here to Skip to main content
14,733,348 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
how to convert string value in drop downlist to integer plz help my code is


dw_subname.SelectedItem.ToString();
Posted
Updated 30-Oct-13 23:36pm
v2
Comments
Kenneth Haugland 31-Oct-13 4:09am
   
Use sselected index instead?
CPallini 31-Oct-13 4:18am
   
Well, generally speaking they are not the same.
Kenneth Haugland 31-Oct-13 4:22am
   
Not entirely sure I follow here...
CPallini 31-Oct-13 4:32am
   
SelectedIndex returns the index value of the item. If, for instance, you have {"5","7","12"} in the list, then the index value is never equal to item content (converted to int, of course).
Kenneth Haugland 31-Oct-13 4:37am
   
Ah yes, but I wasnt really sure about what he wanted, the selected index or the value, he seemed a bit confused... I dont really think he has got an integer value by his comments, but then he needs to clearify the question then :-)
Member 10371894 31-Oct-13 4:23am
   
still i'm having the same error after changing my code to Convert.ToInt32(dw_subname.SelectedItem).ToString();


cannot implicitly convert string to int please help
Member 10371894 31-Oct-13 4:24am
   
still i'm having the same error after changing my code to Convert.ToInt32(dw_subname.SelectedItem).ToString();


cannot implicitly convert string to int please help
Kenneth Haugland 31-Oct-13 4:49am
   
Is selected item a string?
Pheonyx 31-Oct-13 4:12am
   
You cannot convert "Joe Bloggs" to an integer.
What are you actually typing to achieve?

1 solution

See "Int32.Parse Method"[^] and "Int32.TryParse Method"[^]. Both of them allow you to convert the string to an int.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900