如何在没有按钮点击的情况下在第三个文本框中获取两个文本框和? [英] how to get two text box sum in third text box without button click?

查看:112
本文介绍了如何在没有按钮点击的情况下在第三个文本框中获取两个文本框和?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中使用三个文本框,一个是txtPurchase,txtSales和txtProfit

当我输入txtpurchase 5000和txtsale 6000所以我想在txtprofit 1000中显示值而没有按钮click.can有谁建议我该怎么做?



谢谢

hi in my project am using three text boxes one is txtPurchase ,txtSales and txtProfit
when i enter in txtpurchase 5000 and txtsale 6000 so i want to display value in txtprofit 1000 without button click.can anyone suggest me how to do ?

thanks

推荐答案

txtPurchase.Text="5000";
txtSales.Text="6000";





现在Genrate TxtSales选择更改事件(双击设计页面中的文本框以生成事件)





在该事件中编写代码。



Now Genrate TxtSales Selection Changed Event(double click on textbox in design page to genrate event)
and

Write Code in That Event.

protected void txtSales_TextChanged(object sender, EventArgs e)
    {
tProfit.Text=Convert.ToString(Convert.ToInt32(txtPurchase.Text)+Convert.ToInt32(txtSales.Text));
     }


您可以使用textbox的onTextchanged事件来编写添加值的代码。
You can use onTextchanged event of textbox to write the code of adding the values.


试试这个....



Try this....

<div>
        <asp:textbox id="txt1" runat="server" autopostback="true" xmlns:asp="#unknown">
            ontextchanged="txt1_TextChanged"></asp:textbox>
        <asp:textbox id="txt2" runat="server" autopostback="true" xmlns:asp="#unknown">
            ontextchanged="txt2_TextChanged"></asp:textbox>
        <asp:textbox id="txt3" runat="server" autopostback="true" readonly="true" xmlns:asp="#unknown"></asp:textbox>
    </div>













protected void txt1_TextChanged(object sender, EventArgs e)
    {
        if((!string.IsNullOrEmpty(txt1.Text)) && (!string.IsNullOrEmpty(txt2.Text)))
        {
            txt3.Text = (Convert.ToInt32(txt1.Text) + Convert.ToInt32(txt2.Text)).ToString();
        }
    }
    protected void txt2_TextChanged(object sender, EventArgs e)
    {
        if ((!string.IsNullOrEmpty(txt1.Text)) && (!string.IsNullOrEmpty(txt2.Text)))
        {
            txt3.Text = (Convert.ToInt32(txt1.Text) + Convert.ToInt32(txt2.Text)).ToString();
        }
    }


这篇关于如何在没有按钮点击的情况下在第三个文本框中获取两个文本框和?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆