如何从Dropdownlist中选择值时自动填充文本框
问题描述:
以下代码用于从数据库加载下拉列表。但是我希望从文本框中的下拉列表中显示所有数据的选定数据。
following code is for load dropdown list from database. But i want to show a selected data from dropdownlist in textbox with all deails.
protected void load_customer()
{
using (MySqlConnection con = new MySqlConnection(constr))
{
using (MySqlCommand cmd = new MySqlCommand("SELECT concat(firstname, ' ', lastname) as FullName, CustNo FROM tblcustomer order by CustNo"))
{
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
con.Open();
ddCustomer.DataSource = cmd.ExecuteReader();
ddCustomer.DataTextField = "FullName";
ddCustomer.DataValueField = "CustNo";
ddCustomer.DataBind();
con.Close();
}
}
ddCustomer.Items.Insert(0, new ListItem("--Select Customer--", "0"));
}
答
1。处理ddCustomer的SelectedValueChange事件
2.通过ddCustomer.SelectedValue或ddCustomer.Text设置TextBox的Text属性
1. Handling SelectedValueChange event of ddCustomer
2. Set Text property of TextBox by ddCustomer.SelectedValue or ddCustomer.Text