如何从Dropdownlist中选择值时自动填充文本框 [英] How to Auto populate text boxes when selecting value from Dropdownlist
本文介绍了如何从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
这篇关于如何从Dropdownlist中选择值时自动填充文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文