我在Panel中根据数据库的数据,添加了好多个checkbox,然后选中某些值,现在想在程序里把选中的checkbox的ID都找出来,该怎么搞啊?

解决方案 »

  1.   

    foreach(Control control in panelID)
    {
        if(control is CheckBox)
        {
            .....
        }
    }
      

  2.   

    不是吧,没人看啊~~~我自己写了个循环一直报错,各位大侠帮忙看看for (int i = 1; i <= nPageControls3; i++)
            {
                
                foreach (System.Web.UI.Control control in this.Panel3.Controls[i].Controls)
                {
                    if (control is CheckBox)
                    {
                        if (((CheckBox)control).Checked == true)
                        {
                            sqldata.InsetData("hx_jiaose_role", "pj_pid|pj_jid", "" + ((CheckBox)control).ID.ToString() + "|" + constr + "");
                        }
                    }
                }
            }
      

  3.   

    foreach (System.Web.UI.Control control in this.Panel3.Controls[i].Controls)Toforeach (System.Web.UI.Control control in this.Panel3.Controls)
     
      

  4.   

    foreach(Control control in panelID) 
    改为foreach(Control control in panelID.controls)