Click here to Skip to main content
15,564,352 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
HI

I am having a radio button(rbn1) and 3 drop down lists(country,state,city) in my form.
if i select my radio button then *country drop down should be enabled and state and city drop down should be disabled the country drop down list items ( India,USA)

Now if i select the India from list item..then state Drop down list should be enabled
and city drop down should be disabled

Now if i select the USA from list item then city Drop down list should be enabled and state drop down should be disabled.

Is it possible?
Posted
Updated 11-Sep-12 5:27am
v2

 
Share this answer
 
This can be done directly through ASP.NET, Below is Code.

C#
protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
    {
        ddlState.DataSource = res.States(Convert.ToInt16(ddlCountry.SelectedValue));
        ddlState.DataTextField = "StateName";
        ddlState.DataValueField = "StateID";
        ddlState.DataBind();
        ddlState.Items.Insert(0, "Select");
        ddlDist.Enabled = false;
        ddlCity.Enabled = false;
    }
    protected void ddlState_SelectedIndexChanged(object sender, EventArgs e)
    {
        ddlDist.DataSource = res.Districts(Convert.ToInt16(ddlState.SelectedValue));
        ddlDist.DataTextField = "DistName";
        ddlDist.DataValueField = "DistID";
        ddlDist.DataBind();
        ddlDist.Items.Insert(0, "Select");
        ddlDist.Enabled = true;
        ddlCity.Enabled = false;
    }
    protected void ddlDist_SelectedIndexChanged(object sender, EventArgs e)
    {
        ddlCity.DataSource = res.Cities(Convert.ToInt16(ddlDist.SelectedValue));
        ddlCity.DataTextField = "CityName";
        ddlCity.DataValueField = "CityID";
        ddlCity.DataBind();
        ddlCity.Items.Insert(0, "Select");
        ddlCity.Enabled = true;
    }

Full concept of this code is posted here.

http://blog.johnbhatt.com/2012/08/dropdownlist-country-state-district-city.html

you can use UpdatePanel to save page from PostBack.
 
Share this answer
 
v2
Have a look: c# combobox selectedindexchanged events[^]

..and more similar threads on CP Search[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900