简体   繁体   中英

Place selected item from drop down list in to a text box

I want to get a selected item from a drop down list, on button click need to show that selected item into a text box.

I haven't tried anything cause i don't know what to do.

Just use this code...

Suppose, Button click event:

   protected void Button1_Click(object sender, EventArgs e)
    {
       Textbox1.Text = DropDownList1.SelectedItem.Text.ToString();
    }

The following class can give you the general idea of doing what you want.

public class MyClass
{
    public MyClass() 
    {
        comboBox = new ComboBox();
        button = new Button();
        textBox = new TextBox();
        button.Click += OnButtonClick;
    }

    private void OnButtonClick(Object sender, EventArgs e)
    {
        textBox.Text = comboBox.SelectedItem.ToString();
    }

    ComboBox comboBox;
    Button button;
    TextBox textBox;
}

I Have One TextBox And DropDownList1 And Button

To Event ClickButton Write This Code

TextBox1.Text = DropDownList1.Text;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM