Hello All,
I am trying to perform a simple calculation while in the edit or insert twmplate in a FormView. I am using Visual Studio 2005 and C#. I asked this in the C# forum but not much help. Here is what I have now:
protected void Button1_Click1(object sender, EventArgs e)
//declare variables
decimal subtotal10:
decimal hour1010;
decimal hour1011;
decimal hour1020;

//get information from form
hour1010 = ((TextBox)FormView1.FindControl("Hours1010TextBox"));
hour1011 = ((TextBox)FormView1.FindControl("Hours1011TextBox"));
hour1020 = ((TextBox)FormView1.FindControl("Hours1020TextBox"));

//calculate hours
subtotal10 = hour1010 + hour1011 + hour1020 *1;

//display hours
TextBox a = (TextBox)FormView1.FindControl("SubHours10TextBox");
a.Text = subtotal10;

The user inputs number of hours in then clicks a calc button. I am getting errors in several different areas as I change it. Like Can not convert string to int or int to string. Most of the errors happen in 2 areas the get information area or the display area.

Any Suggestions I am beginning to think that this can not be done in FormView.

Thanks for your help.

9 Years
Discussion Span
Last Post by GeneM

Found it. I was casting at the wrong time. I needed my variables as string, then convert to double then parse.
Here It is:
protected void Button1_Click(object sender, EventArgs e)
string num1 = ((TextBox)FormView1.FindControl("num1TextBox")).Text;
string num2 = ((TextBox)FormView1.FindControl("num2TextBox")).Text;
double total;
total = double.Parse(num1) + double.Parse(num2);
((TextBox)FormView1.FindControl("totalTextBox")).Text = total.ToString();
//This gave me a concatination
//((TextBox)FormView1.FindControl("totalTextBox")).Text = ((TextBox)FormView1.FindControl("num1TextBox")).Text + ((TextBox)FormView1.FindControl("num2TextBox")).Text;
Hope this helps someone.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.