tags:

views:

16

answers:

0

I have a dropdown list that searched a column in database table and returns items to listbox in DDL's selectchange event. In this same event I want to include code that will populate teh listbox with items that where in it before search if user deselect , i. e. if ProjDDL.selecteditem.value = "--". Please help me with the code. protected void ProjDDL1_SelectedIndexChanged(object sender, EventArgs e) { String ProjectDDL1 = ProjDDL1.SelectedItem.Value; String ProjectDDL2 = ProjDDL2.SelectedItem.Value; String ProjectDDL3 = ProjDDL3.SelectedItem.Value; String ProjectDDL4 = ProjDDL4.SelectedItem.Value; String ProjectDDL5 = ProjDDL5.SelectedItem.Value; //String ColumnName = "Business"; ClientPJ mypj = new ClientPJ((DataSet)(Session["Client_ProjectDS"])); ListItemCollection DS4DDL1Before = ProjList.Items; //<-------copy listbox item before search if (ProjectDDL1 != "--") {

        ListItemCollection DS4DDL1 = mypj.searchPJ(ProjList.Items, ProjectDDL1);
                    ProjList.Items.Clear();
        ProjList.DataSource = DS4DDL1;
        ProjList.DataTextField = "Text";
        ProjList.DataValueField = "Value";
        ProjList.DataBind();
    }
    if (ProjectDDL1 == "--")
    {
        ListItemCollection DS4DDL1 = DS4DDL1Before;//<-- Not showing any items in listbox???
        ProjList.Items.Clear();
        ProjList.DataSource = DS4DDL1;
        ProjList.DataTextField = "Text";
        ProjList.DataValueField = "Value";
        ProjList.DataBind();


    }

    if (ProjectDDL2 != "--")
    {
        //ColumnName = "Business_group";
        //DS4DDL1 = mypj.searchProject(ProjList.Items, ProjectDDL2, ColumnName);
        ListItemCollection DS4DDL2 = mypj.searchPJ(ProjList.Items, ProjectDDL2);
        ProjList.Items.Clear();
        ProjList.DataSource = DS4DDL2;
        ProjList.DataTextField = "Text";
        ProjList.DataValueField = "Value";
        ProjList.DataBind();
    }