Hi guys,

I've been trying to update an updatepanel with the selected values of two dropdownlists. The updatepanel is supposed to be updated on selectedindex changed of the second dropdown. The update works on the first initial index changed, but does not work for any subsequent index change.

The markup is as such:

<asp:UpdatePanel runat="server" ID="pnl1" UpdateMode="Always">
    <ContentTemplate>
        <div id="blah" runat="server" class="well well-large" style="height:100px;">
        <asp:DropDownList ID="ddl1" runat="server" OnSelectedIndexChanged="func1_click" AutoPostBack="true" /><br />
        <asp:DropDownList ID="ddl2" runat="server" OnSelectedIndexChanged="func2_click" AutoPostBack="true"  />
        </div>
    </ContentTemplate>
</asp:UpdatePanel>

<asp:UpdatePanel runat="server" ID="pnl2" UpdateMode="Always">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="ddl2" EventName="SelectedIndexChanged" />
        </Triggers>
        <ContentTemplate>
            <asp:Label ID="lbl" runat="server" />
        </ContentTemplate>
</asp:UpdatePanel>

The Codebehind functions:

protected void func1_click(object sender, EventArgs e)
{
    if (ddl1.SelectedValue == "")
        ddl2.Visible = false;
    else
    {
        SqlCommand cmd = new SqlCommand("SELECT blah blah...", con);
        con.Open();
        cmd.Parameters.AddWithValue("@id", ddl1.SelectedValue);

        ddl2.DataSource = cmd.ExecuteReader();
        ddl2.DataTextField = "text";
        ddl2.DataValueField = "value";
        ddl2.DataBind();
        ddl2.Items.Insert(0, new ListItem("--Select--", ""));
        ddl2.SelectedIndex = 0;
        ddl2.Visible = true;
    }
}

protected void func2_click(object sender, EventArgs e)
{
    lbl.Text = ddl1.SelectedItem + " > " + ddl2.SelectedItem;
}

When I try to toggle the the second dropdownlist more than once, it does not update the update panel. I have to toggle the first dropdownlist and then the second dropdownlist to see results. If this is not clear, please let me know. Thanks for your help!

Hi,
Do your code behind functions fire on postback?

func1 always fires, func2 fires on the first indexchange, but not subsequent index changes

Upon further investigation, ddl2 always defaults to the value of the first index. Postback issue?

Be sure to register both dropdowns in the scriptmanager.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.