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;
FormView1.FindControl("TotalHoursTextBox").Focus();
}

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.
gene

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.
gene

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.