日期:2014-05-17  浏览次数:20503 次

ASP.NET动态生成Checkbox并取值,在线等解
需要动态生成Checkbox,并取得Checkbox的值
.cs中动态生成Checkbox的代码:

 public void GetPanelControl()
        {
            DataTable dt = DataLayer.GetAllPEQUIPSource();
            
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                CheckBox ckbox = new CheckBox();
                ckbox.AutoPostBack = false;
                string str= dt.Rows[i]["PIP"].ToString();
                int count = str.Length;
                ckbox.Text = str.Substring(str.LastIndexOf('.')+1,2);
                
                ckbox.ID = "ckbox" + i;
                this.panList.Controls.Add(ckbox);
            }
        }

现在如何能取到Checkbox的值???
我每次点击提交按钮时,生成的Checkbox都消失了,什么原因???
动态生成Checkbox?? 遍历Checkbox

------解决方案--------------------
动态创建checkbox和获取值:
http://www.cnblogs.com/insus/archive/2013/04/23/3035447.html
------解决方案--------------------
遍历控件
void IterateThroughChildren(Control parent)   //遍历所有控件
    {
      foreach (Control c in parent.Controls)