如何在没有按钮点击的情况下在第三个文本框中获取两个文本框和?

如何在没有按钮点击的情况下在第三个文本框中获取两个文本框和?

问题描述:

在我的项目中使用三个文本框,一个是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();
        }
    }