在自动完成文本框中选择名称,然后在第二个文本框中加载手机号码

本文关键字:文本 然后 第二个 加载 手机号码 选择 | 更新日期: 2023-09-27 17:59:24

我的数据库表中有两个字段:namemobile no,以及表单中的两个文本框。我的第一个文本框是通过从数据库中获取名称来自动完成文本框。我希望当我在文本框中选择name时,在第二个文本框中加载mobile no。有人能帮忙吗?

private void textBox1_TextChanged(object sender, EventArgs e)
{
    AutoComplete();
}
public void AutoComplete()
{
    SqlConnection conn = new SqlConnection(@"Database Source.....");
    conn.Open();
    AutoCompleteStringCollection AutoItem = new AutoCompleteStringCollection();
    SqlCommand command = new SqlCommand("select * from table1", conn);
    SqlDataAdapter adp = new SqlDataAdapter(command);
    DataTable tbl = new DataTable();
    adp.Fill(tbl);
    foreach (DataRow rw in tbl.Rows)
    {
        AutoItem.Add(rw["name"].ToString());
    }
    textBox1.AutoCompleteMode = AutoCompleteMode.Suggest;
    textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
    textBox1.AutoCompleteCustomSource = AutoItem;
}

在自动完成文本框中选择名称,然后在第二个文本框中加载手机号码

您需要在文本选择后激发一些事件,例如给定一个类似Get Mobile No的按钮,然后单击该按钮的事件使用名称获取移动no

相关文章: