0

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?

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by Nfurman
2

Hi,

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;
            else
                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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.