Note that there are some explanatory texts on larger screens.

plurals
  1. PODropDown List resets to the first item and doesn't return a selectedvalue
    text
    copied!<p>So I have a country dropdownlist and a state dropdownlist which is being populated dynamically based off of the country chosen. When I click the country the state dropdown gets populated just fine but the problem arises when I click a value (state) from the other dropdown, the list instead of retaining the selected item will go back to the first item of the list and no selectedvalue are displayed.</p> <pre><code>&lt;td&gt;&lt;asp:DropDownList ID="ddlState" runat="server" DataSourceId="dsStateList" DataTextField="state_nm" DataValueField="state_cd" OnSelectedIndexChanged="ddlState_SelectedIndexChanged" AutoPostBack="true" AppendDataBoundItems="true" Width="160px" OnDataBound="ddlState_OnDataBound"&gt; &lt;/asp:DropDownList&gt; &lt;/td&gt; &lt;asp:DropDownList ID="ddlCountry" runat="server" DataSourceId="dsCountryList" DataTextField="COUNTRY_NAME" DataValueField="COUNTRY_CIA_ID" OnSelectedIndexChanged="ddlCountry_SelectedIndexChanged" OnDataBound="ddlCountry_OnDataBound" AutoPostBack="true" AppendDataBoundItems="true" Width="160px"&gt; &lt;/asp:DropDownList&gt; protected void ddlState_SelectedIndexChanged(object sender, EventArgs e) { string comboStateCODE = ddlState.SelectedValue; dsCompanyListParam.Text = comboStateCODE; ddlCountry.DataBind(); ddlState.DataBind(); } protected void ddlState_OnDataBound(object sender, EventArgs e) { ddlState.Items.Insert(0, "Please Select a State"); } protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e) { ddlState.Items.Clear(); dsStateList.SelectParameters["iCountryID"].DefaultValue = ddlCountry.SelectedValue; dsCompanyListParam.Text = ddlCountry.SelectedValue; Trace.Warn("ddlCountry_SelectedIndexChanged"); ddlCountry.DataBind(); ddlState.DataBind(); } protected void ddlCountry_OnDataBound(object sender, EventArgs e) { ddlCountry.Items.Insert(0, "Please Select a Country"); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload