Pregunta

I want to change the text of a textbox based on the value selected in the dropdown. This is the code i wrote

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
    int a = 2;
    int b = 3;


    if (DropDownList1.SelectedValue == "Manager")

        TextBox7.Text = Convert.ToString(a);

    else if (DropDownList1.SelectedValue == "Front office")
        TextBox7.Text = Convert.ToString(b);

}

When i select the value from the drop down the value doesn't change in the text box.

Any help will be appreciated.

¿Fue útil?

Solución

You need to make sure you set "AutoPostBack" to true on your DropDownList.

<asp:DropDownList = runat="server" ID= "DropDownList1" AutoPostBack="True">
</asp:DropDownList>

Unlike with desktop applications, the code you write in your event handlers won't fire until the aspx page posts back to the server (refreshes).

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top