I am performing a calculation inside a FormView Insert Template using Visual Studio 2005 and C#. The calculation works fint until a TextBox is left empty. Then I get an expected error message;
Input string was not in a correct format.
There are 100 TextBoxes on this form at which any 80% can be left blank. This is acceptable.
The TextBoxes are databound and if I change the text in the properties, I lose the databind.
This is where I need help;
I need to populate the TextBoxes with a value if the user has not so the calculation can continue.
Here is my code so far;
protected void Button1_Click(object sender, EventArgs e)
{
string num1 = ((TextBox)FormView1.FindControl("num1TextBox")).Text;
string num2 = ((TextBox)FormView1.FindControl("num2TextBox")).Text;
string num3 = ((TextBox)FormView1.FindControl("num3TextBox")).Text;
double total;
total = double.Parse(num1) + double.Parse(num2) + double.Parse(num3);
((TextBox)FormView1.FindControl("totalTextBox")).Text = total.ToString();
}
Again if all boxes are filled it works fine.
Thanks,
gene