I was answering some questions on the www.asp.net forms where I came across an interesting post which deals with the error "Input string is not in the correct format". The situation was that converting the label text to the integer value. The code that was generating error was:
private void FormatTesting()
{
Label1.Text = "34.45";
try
{
int myInt = Int32.Parse(Label1.Text);
}
catch (Exception ex)
{
lblMsg.Text = ex.Message;
}
}
The reason is that the label text is in the double format since it includes the decimal point and the Int32.Parse is not able to parse the text as integar. This can be easily fixed using the following code:
private void FormatTesting()
{
Label1.Text = "34.34";
try
{
double myDouble = Double.Parse(Label1.Text);
}
catch (Exception ex)
{
lblMsg.Text = ex.Message;
}
}
or if you really want the int you can the string "34" instead of "34.34". I hope this helps!