Hi,
I have two textboxes(which are diplay only;their values come from database).I need read the data from these textboxes,multiply them and display in the third text box.
Can someone send me the code.
For example consider textboxes names as txtprice,txtquantity,txtamount;

txtprice,txtquantity values come from tables in database.The price comes from Table COst and quantity comes from Table Inventory.
I want to diplay result in txtamount.

Recommended Answers

All 7 Replies

txtamount.Text = (Int32.Parse(txtprice.Text) * Int32.Parse(txtquantity.Text)).ToString(); // Integer values
txtAmount.Text = (Double.Parse(txtprice.Text) * Double.Parse(txtquantity.Text)).ToString(); // Real values

Thanks a lot.One more question.How to calculate the grand total?(Sum of all the amounts)

grand total of all values from database or grand total of these two textboxes?

int sum=0;
for(int i=0;i<yourvalues.Length-1;i++)
{
sum+=(Int32.Parse(yourvalues[i]));
}

Read values from database into string array yourvalues;

grand total of textboxes

TextBox[] tbs = new TextBox[] { textBox1, textBox2 };
decimal total = 0M;
for(int i = 0; i < tbs.Lenght; i++)
     total += ConvertToDecimal(tbs[i].Text);

Sorry for my ignorance.But the 4th textbox is Txtbox4 should I replace Textbox[] with txtbox4[]?

Cmon people!Somebody help me

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.