Hello again

I have two drop-down lists on my web application.

#1. Country list
#2. US states list

By default #2 is disabled

protected void Page_Load(object sender, EventArgs e)
        State.Enabled = false;  

I need to enable it only if user will choose "United States".
My trial was as such:

private void CheckIfAmerican()
        if (Country.Text == "United States") //Country is the name of #1 ddlist
            State.Enabled = true; //State is the name of 2# ddlist

How to implement this case?


Here is the simple idea;

1) Use the "SelectedIndexChanged" event and call your function. A simple example;

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
            if (DropDownList1.Text == "US")
                DropDownList2.Enabled = true;
                DropDownList2.Enabled = false;

2) Eliminate the "State.Enabled = false;" from page_load event since it will be fired every server request.

3) Do not forget to set the "AutoPostBack" property to set "true"

Good luck.

thank you very much! it works