FineUI 官方论坛

标题: 如果取到动态添加到页面中的FineUI控件的值? [打印本页]

作者: yjdabc    时间: 2016-11-18 16:33
标题: 如果取到动态添加到页面中的FineUI控件的值?
我在后台动态生成一个FineUI checkBoxList控件,然后添加到simpleForm中,
protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                FineUI.CheckBoxList cbl1 = new FineUI.CheckBoxList();
                cbl1.ID = "myID";
                cbl1.Items.Add(new CheckItem("yin", "1"));
                cbl1.Items.Add(new CheckItem("qu", "2"));
                this.simpleForm1.Items.Add(cbl1);
            }
        }

然后我在后台方法中想取到用户选择的值:
if (this.simpleForm1.FindControl("myID") != null)
            {
                FineUI.CheckBoxList cbl1 = this.form1.FindControl("myID") as FineUI.CheckBoxList;
                for (int i = 0; i < cbl1.Items.Count(); i++)
                {
                    CheckItem cb = cbl1.Items[i];
                    if (cb.Selected)
                    {
                        l1.Text += cb.Text;
                    }
                }               
            }

但始终显示取不到,请问该怎么解决?


作者: 雨天不打伞    时间: 2016-11-19 16:41
        /// <summary>
        /// 在父控件的所有子控件中查找控件
        /// </summary>
        /// <param name="control">父控件</param>
        /// <returns>找到的控件</returns>
        public static Control FindControl(Control control, String controlID)
        {
            if (control != null && control.Controls.Count > 0)
            {
                foreach (Control c in control.Controls)
                {
                    if (c != null && c.ID == controlID)
                    {
                        return c;
                    }
                    else
                    {
                        Control childControl = FindControl(c, controlID);
                        if (childControl != null)
                        {
                            return childControl;
                        }
                    }
                }
            }

            return null;
        }





欢迎光临 FineUI 官方论坛 (https://fineui.com/BBS/) Powered by Discuz! X3.4