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事件无效。请帮帮我