Click here to Skip to main content
14,825,425 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I need to multiply values in two textbox
box3 datatype is Int
box4 datatype is float
box5 datatype is float(result)

box5.Text = box3.Text * box4.Text;

Could you please help me to solve this

Updated 7-Dec-11 21:40pm

Try this one:
float result = Convert.ToInt32(box3.Text) * Convert.ToSingle(box4.Text);
box5.Text = result.ToString();

Ganesan Senthilvel 8-Dec-11 4:05am
this should be perfect
[no name] 8-Dec-11 4:13am
Sravan S 8-Dec-11 6:55am
yeah, this is the best way to meet d requirement.
Sravan S 8-Dec-11 7:06am
but still you will get error when the values entered are non numeric in the text boxes... :(
[no name] 8-Dec-11 21:11pm
validation is not my problem anymore :) 9-Dec-11 0:11am
Thanks if it is dynamic column how to do the multiplication?
[no name] 9-Dec-11 0:24am
It would be the same. You need to iterate thru all your columns using
foreach(GridViewColumn col in GridView1.Columns)
// code here
} 9-Dec-11 2:59am
Hi could you pls help GridViewRow iam able to use for GridViewColumn getting error as "Error 3 The type or namespace name 'GridViewColumn' could not be found (are you missing a using directive or an assembly reference? need to add any reference
box5.Text = (Convert.ToDouble(Convert.ToDouble(box3.Text) * Convert.ToDouble(box4.Text))).ToString();
The following would be more perfect because in the above solutions you will get an error when user enters non numeric values( like alphabets or symbols).But with the following code u wont get error. instead you will get value as 0.
 int box3value;
float box4value,result;
int.tryparse(box3.text,out box3value);
float.tryparse(box4.text,out box4value);

Hope this will help you for sure.
Convert.ToInt64(box5.Text) = Convert.toInt64(Convert.toInt32(box3.Text) * Convert.toInt64(box4.Text));

May br this'll help you out
Sravan S 8-Dec-11 6:54am
by following this you will lose the float value as it will be converted into int. Say for value in box4 is 4.2 then Convert.toInt64(box4.Text) results in 4 which is not wat u want.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900