Click here to Skip to main content
15,886,632 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to convert a string to an int like this and to increment it:
count = Convert.ToInt32(Hidden_id.Value) + 1;
but results this error: Input string was not in a correct format.
Posted

1 solution

The string in Hidden_id.Value is not an integer - it contains characters which are not numeric.

Either use int.TryParse instead, or check what you are loading into the field, as it is not a valid number!
 
Share this answer
 
Comments
lovitaxxxx 30-Nov-12 8:41am    
it gives me error even doing this:
int count = int.Parse(Hidden_id.Value);
even this one:
int count = Convert.ToInt32(Hidden_id.Value);
OriginalGriff 30-Nov-12 8:59am    
That is why I said use TryParse, not Parse - it reports a problem via the bool return value if the conversion fails, rather than throwing an exception.
But you need to look at what is in the value, and how it got there since the user can't enter a value to a Hidden field.
lovitaxxxx 30-Nov-12 8:41am    
how to convert a hidden field value to int?
codeninja-C# 30-Nov-12 9:04am    
Annaa,
can you provide your Hidden_id.Value?
--SJ
lovitaxxxx 30-Nov-12 9:02am    
I want the hidden value to keep nje row index of the datatable.. so to store it during the navigation through records

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