Stack Over
Stack Over

Reputation: 635

How can I trigger dropdown while viewing asp.net page

There are two Dropdown in the asp.net page. When I select first one (city), the second one (district) is triggered.

I have a save button for the page.

When I click the save button, I write the SelectedValues of dropdowns in to the database. And when I open the page again, I assign the values to the dropdown's selected values.

The first one is ok when I assign dropdown.SelectedValue = "5" but the second one is not triggered. How can I trigger it?

Thanx.

Upvotes: 1

Views: 307

Answers (1)

Nisha
Nisha

Reputation: 1439

I have done the same thing. Suppose you have drop down say ddlCountry and ddlCity. You need to load all cities just for the selected country.

protected void Page_Load(object sender, EventArgs e)
{
    if(!IsPostBack)
    {
       LoadCountriesInDropDown(ddlCountry);
       ddlCountry.SelectedValue = "5" //For eg:
       LoadCitiesByCountrySelected(ddlCity, ddlCountry.SelectedValue);  // selected country value was set here as 5
       ddlCountry_SelectedIndexChanged(null, null);
    }
}
protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
{
    if(ddlCountry.SelectedItem.Text == "Select")
    {
        ddlCity.Items.Clear();
    }
    else
    {
        LoadCitiesByCountrySelected(ddlCity, ddlCountry.SelectedValue);
    }

}

Hope this was what you wanted.

Upvotes: 1

Related Questions