如何在textbox textchanged事件后更改文本框值?

时间:2014-11-26 07:55:05

标签: c#

我有两个文本框Textbox1Textbox2。我想根据textbox1值在textbox2中带一些值。我有一个查询

protected void TextBox1_TextChanged(object sender, EventArgs e)
    {
     string str="select TimeIn from Employee where Date='"+txtdate.text+"'";
     Sqldatreader dr=conn.query(str);
     if(dr.Read())
     {
     Textbox2.text=dr[0].Tostring();
     }
   }

3 个答案:

答案 0 :(得分:0)

    private void textBox1_TextChanged(object sender, EventArgs e)
    {
        textBox2.Text = textBox1.Text;
    }

答案 1 :(得分:0)

您必须更改AutoPostBack= True的属性TextBox1,然后将其作为

进行更改
private void textBox1_TextChanged(object sender, EventArgs e)
    {
        textBox2.Text = textBox1.Text;
    }

答案 2 :(得分:0)

string SelectCustomerBalance = "Select cbalance FROM customer where cname = '" +  
                               searchLookUpEdit1.Text + "'";

con.Open();
SqlCommand cmd = new SqlCommand(SelectCustomerBalance, con);
SqlDataReader datareader = cmd.ExecuteReader();
// con.Close();
if (datareader.Read())
  {
     txtcustomercurrentBlnc.Text = datareader["cbalance"].ToString();
  }