0

我已经在面板中动态创建了 ListBox,我想从动态创建的 Listbox 中读取所选项目。下面是我用来创建动态列表框的代码。谁能帮助我如何获取动态创建的列表框,然后阅读所选项目。'受保护的无效GotoReport_Click(对象发送者,ImageClickEventArgs e){

        foreach (TreeNode tndim in tvCubedef.CheckedNodes)
        {

            lbFilter.Items.Add(tndim.Text);

        }
        foreach (ListItem item in lbFilter.Items)
        {
            item.Selected = true;
        }

        panFilter.Controls.Clear();
        connstr2 = System.Configuration.ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString;
        conn2.ConnectionString = connstr2;
        conn2.Open();
        CubeCollection CubeList = conn2.Cubes;
        string cb = ddlCubeList.SelectedItem.Text;

        foreach (ListItem li in lbFilter.Items)
        {

            ListBox listb = new ListBox();
            ListItem Memlist = new ListItem();
            listb.SelectionMode = System.Web.UI.WebControls.ListSelectionMode.Multiple;
            listb.Height = 150;
            listb.Width = 250;

            string Repl1 = li.Value.Replace("[", "");
            string Repl2 = Repl1.Replace("]", "");
            string[] DimMember = Repl2.Split('.');
            foreach (Member dimem in CubeList[cb].Dimensions[DimMember[0]].Hierarchies[DimMember[1]].Levels[DimMember[2]].GetMembers())
            {

                Memlist.Text = dimem.Name;
                listb.Items.Add(Memlist);
                panFilter.Controls.Add(listb);

            }

        }


    } '
4

1 回答 1

0

您需要动态添加事件处理程序:

listb.SelectedIndexChanged += new EventHandler(listb_SelectedIndexChanged);

当然你还需要提供这个方法:

protected void listb_SelectedIndexChanged(Object sender, EventArgs e)
{
    ListBox listb = (ListBox) sender;
}

您是否最晚ListBox 在每次回发(如您应该)上重新创建此内容并与以前相同?page_loadID

于 2012-11-30T08:17:51.963 回答