protected override void OnInit(EventArgs e)
    {
        ListBox lst = new ListBox();

        lst.Attributes["class"] = "cat-list";

        lst.DataSource = cat.list(Convert.ToInt32(0));
        lst.DataTextField = "catName";
        lst.DataValueField = "catId";
        lst.DataBind();


        lst.AutoPostBack = true;
        lst.SelectedIndexChanged += Lst_SelectedIndexChanged;

        Panel pnl = new Panel();
        pnl.Attributes["class"] = "col-sm-2 col-xs-12";
        pnl.Controls.Add(lst);

        categories.Controls.Add(pnl);
    }

    private void Lst_SelectedIndexChanged(object sender, EventArgs e)
    {
        ListBox listBox = (ListBox)sender;
        ListBox lst = new ListBox();

        lst.Attributes["class"] = "cat-list";

        lst.DataSource = cat.list(Convert.ToInt32(listBox.SelectedValue));
        lst.DataTextField = "catName";
        lst.DataValueField = "catId";
        lst.DataBind();


        lst.AutoPostBack = true;
        lst.SelectedIndexChanged += Lst_SelectedIndexChanged;

        Panel pnl = new Panel();
        pnl.Attributes["class"] = "col-sm-2 col-xs-12";
        pnl.Controls.Add(lst);

        categories.Controls.Add(pnl);
    }

The first Listbox selectedindexchanged event working but second Listbox selectedindexchanged event not working. If I select a option on second listbox, second listbox lost.Just keep selected option on first listbox. What can I do about that? Please help me.

Related posts

Recent Viewed