Click here to Skip to main content
15,895,746 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


C#
dw_subname.SelectedItem.ToString();
Posted
Updated 30-Oct-13 22: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 :-)

1 solution

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

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