Click here to Skip to main content
15,922,007 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
following code is for load dropdown list from database. But i want to show a selected data from dropdownlist in textbox with all deails.
C#
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"));
}
Posted
Updated 7-Dec-15 8:51am
v2

1 solution

1. Handling SelectedValueChange event of ddCustomer
2. Set Text property of TextBox by ddCustomer.SelectedValue or ddCustomer.Text
 
Share this answer
 
Comments
SPhutane 7-Dec-15 23:18pm    
Not working.
Dropdownlist resets to select customer and in textbox shows value 0.
Ngo Tuong Dan 8-Dec-15 5:01am    
try Set Text property of TextBox by ddCustomer.Text

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900