我想要使用textchange事件加总 [英] i want sum using textchange event
问题描述
protected void txtOtherCharge_TextChanged(object sender,EventArgs e)
{
txtTotal1.Text =(Convert.ToInt32(txtCasecharge.Text) )+ Convert.ToInt32(txtDoctCharge.Text)+ Convert.ToInt32(txtWardcharge.Text)+ Convert.ToInt32(txtOtherCharge.Text).ToString());
}
使用此其他费用值总计不起作用
首先,不要使用转换为用户输入的值:如果用户输入错误,它将使您的网站崩溃 - 这可能是这里发生的事情。相反,使用TryParse:
int caseCharge;
if (!int.TryParse(txtCarecharge.Text, out caseCharge))
{
// 向用户报告问题
返回跨度>;
}对每个文本框重复一遍,然后:
txtTotal1.Text =(caseCharge + doctCharge + wardCharge + otherCharge).ToString();应该可以工作。
在这个字符串的末尾有一个ToString().-转换。 ToInt32(txtOtherCharge.Text).ToString()
也许你在尝试
(Convert.ToInt32(txtCasecharge.Text)+ Convert.ToInt32(txtDoctCharge.Text)+ Convert.ToInt32(txtWardcharge.Text)+ Convert.ToInt32(txtOtherCharge.Text))。ToString();
protected void txtOtherCharge_TextChanged(object sender, EventArgs e)
{
txtTotal1.Text = (Convert.ToInt32(txtCasecharge.Text) + Convert.ToInt32(txtDoctCharge.Text) + Convert.ToInt32(txtWardcharge.Text) + Convert.ToInt32(txtOtherCharge.Text).ToString());
}
using this other charge value is not working in total
First off, don't use Convert for user entered values: if the user mistypes, it will crash your site - which is probably what is happening here. Instead, use TryParse:
int caseCharge; if (!int.TryParse(txtCarecharge.Text, out caseCharge)) { // Report problem to user return; }Repeat that for each of your text boxes, then:
txtTotal1.Text = (caseCharge + doctCharge + wardCharge + otherCharge).ToString();Should work.
There is a ToString() at the end of this string.-Convert.ToInt32(txtOtherCharge.Text).ToString()
Perhaps you were trying
(Convert.ToInt32(txtCasecharge.Text) + Convert.ToInt32(txtDoctCharge.Text) + Convert.ToInt32(txtWardcharge.Text) + Convert.ToInt32(txtOtherCharge.Text)).ToString();
这篇关于我想要使用textchange事件加总的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!