如何将两个文本框的和值插入第三个文本框 [英] how to insert sum value of two text box into third text box
本文介绍了如何将两个文本框的和值插入第三个文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表单中的三个文本框和两个与textbox1和textbox2相关联的复选框.
另一个文本框被命名为grandtotal.当我选中复选框时,它将在两个文本框中插入值.现在,我想将值的总和插入到名为grandtotal
的第三个文本框中
以下是文本框1和文本框1的我的代码
I have three text boxes in a form and two check box associated to textbox1 and textbox2.
Another textbox is named as grandtotal. When I checked on check box it insert value in two text boxes. Now I want to insert sum of value into third text box which is named as grandtotal
Below are the my codes for the text box 1 and text box 1
private void checkBoxAdmission_CheckedChanged(object sender, EventArgs e)
{
SQLHelper objsql = new SQLHelper();
objsql.SqlText = " select SettingID,SettingValue from tblSettings where SettingID = 1";
objsql.AddParameter("FeetypeID", checkBoxAdmission.Checked);
DataTable dt = objsql.getDataTable(false);
if (dt.Rows.Count > 0)
txtAdmissionFee.Text =dt.Rows[0]["SettingValue"].ToString();
objsql.Close();
objsql.Dispose();
}
private void checkBoxMonthly_CheckedChanged(object sender, EventArgs e)
{
SQLHelper objsql = new SQLHelper();
objsql.SqlText = " select SettingID,SettingValue from tblSettings where SettingID = 2";
objsql.AddParameter("FeetypeID", checkBoxMonthly.Checked);
DataTable dt = objsql.getDataTable(false);
if (dt.Rows.Count > 0)
txtMonthlyFee.Text = dt.Rows[0]["SettingValue"].ToString();
objsql.Close();
objsql.Dispose();
}
private void txtGrandTotal_TextChanged(object sender, EventArgs e)
推荐答案
您可以将第二个复选框本身填充到第三个文本框中,如下所示...
You can fill the third textbox with the second checkbox click itself like below...
private void checkBoxMonthly_CheckedChanged(object sender, EventArgs e)
{
// Declare grandTotal. Take datatype as per your requirement.
int grandTotal;
SQLHelper objsql = new SQLHelper();
objsql.SqlText = " select SettingID,SettingValue from tblSettings where SettingID = 2";
objsql.AddParameter("FeetypeID", checkBoxMonthly.Checked);
DataTable dt = objsql.getDataTable(false);
if (dt.Rows.Count > 0)
txtMonthlyFee.Text = dt.Rows[0]["SettingValue"].ToString();
objsql.Close();
objsql.Dispose();
// Add values and fill to third textbox.
grandTotal = Convert.ToInt32(txtAdmissionFee.Text) + Convert.ToInt32(txtMonthlyFee.Text);
txtGrandTotal.Text = grandTotal.ToString();
}
注意:根据您的要求采用数据类型和转换机制.
谢谢...
NOTE: Take datatype and conversion mechanism as per your requirements.
Thanks...
这篇关于如何将两个文本框的和值插入第三个文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文