列表框selectedindexchanged

时间:2016-07-30 14:01:27

标签: c# asp.net listbox selected

    private void cat_SelectedIndexChanged(object sender, EventArgs e)
    {
        ListBox listBox = (ListBox)sender;

        ListBox lst = new ListBox();
        lst.Attributes["class"] = "cat-list";
        lst.Attributes["id"] = "ListBox" + id.ToString();
        lst.Attributes["OnSelectedIndexChanged"] = "cat_SelectedIndexChanged";
        lst.AutoPostBack = false;
        lst.SelectedIndexChanged += cat_SelectedIndexChanged;
        lst.DataSource = ktg.list(Convert.ToInt32(listBox.SelectedValue));
        lst.DataTextField = "catName";
        lst.DataValueField = "catId";
        lst.DataBind();

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

        kategoriler.Controls.Add(pnl);
        id++;
    }

如果autopostback=true,则列表框未保持选中但如果autopostback=false,则cat_selectedIndexChanged事件无效。请帮帮我

0 个答案:

没有答案