I have 8 textboxes that only accept integers. How to calculate the total of value entered by users in each textbox and the result will be showed as a label. After user click on submit button, the the value of the label(result of numbers) will be stored in db. Anyone knows? Thank you. Looking forward to hear from u guys.
I got this error : Input string was not in a correct format.
At this line:
int total = 0;
total = int.Parse(TextBox2.Text) + int.Parse(TextBox4.Text) + int.Parse(TextBox6.Text) + int.Parse(TextBox8.Text) + int.Parse(TextBox10.Text) + int.Parse(TextBox12.Text) + int.Parse(TextBox14.Text) + int.Parse(TextBox16.Text);
Label1.Text = total.ToString();
You can do this way:-
Store the value in label
OR
foreach (Control c in this.Controls){
if (c.GetType().Name.ToString()==”TextBox”)
{
totalValue += int.Parse(String.Format(“txtBox{0}.Text”, count));
}
}
Store the value in label