开发者

DDL Second iteration does not 'rest' cascading drop down

开发者 https://www.devze.com 2022-12-18 17:32 出处:网络
I have the following code that a cascading drop down kicks off with protected void ddlBuyer_SelectedIndexChanged(object sender, EventArgs e)

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 开发者_C百科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--");
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号