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.

有帮助吗?

解决方案

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).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top