سؤال

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