简体   繁体   中英

DDL Second iteration does not 'rest' cascading drop down

I have the following code that a cascading drop down kicks off with

protected void ddlBuyer_SelectedIndexChanged(object sender, EventArgs e)
{
    FinalProductsDataContext dbII = new FinalProductsDataContext();
    var queryBuyer = (from r in dbII.tblOnlineReportingFINALPRODUCTSNEWDEMOs
                      where r.UnitUserfield1 == ddlBuyer.SelectedValue
                      select new { UnitUserfield2 = r.UnitUserfield2 }).Distinct().OrderBy(r => r.UnitUserfield2);

    ddlSub.DataSource = queryBuyer;
    ddlSub.DataTextField = "UnitUserfield2";
    ddlSub.DataValueField = "UnitUserfield2";
    ddlSub.DataBind();

    GridView1.Columns.Clear();

    tbxProdAC.Text = "";

    radSub.Checked = false;
    radProd.Checked = false;
    radProdAC.Checked = false;

    radBuyer.Checked = true;

    ddlProd.Items.Insert(0, "--Choose Product--");
    ddlSub.Items.Insert(0, "--Choose Sub Category--");

}

On it's first run through, this runs perfectly with ddlProd & ddlSub being populated with "--Choose..."

However, if the user changes ddlBuyer, ddlSub, ddlProd and then back to change the ddlBuyer, ddlSub is populated with "--Choose Sub-Category--" but ddlProd remains as the first item they looked at.

How can I get around this?

try to add

ddlProd.SelectedIndex = 0;

after

ddlProd.Items.Insert(0, "--Choose Product--");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM