我的代码是这样的我用了个panel,用循环,for(int i=0;i<ds.Tables[0].Rows.Count;i++)
                                 {
                                     checkbox ab=new checkbox();
                                     string str=ds.Tables[0].Rows [i][字段名].Tostring();
                                     ab.ID="ab"+i.Tostring();
                                     ab.Text=str;
                                     this.Panel1.Controls.Add(ab);//此步在panel1里动态生成了多个checkbox
      请问各位高手,我是菜鸟,如何用循环来取的这些checkbox的值呢???                    
                                 

解决方案 »

  1.   

    (checkbox)this.panel1.FindContrlo("ab1").Text 这样可以取到特定的一个checkbox值,可是我想取多个呢?我知道可以用循环,是利用ID吗,请指教,可否用ArrayList 呢 ???迷糊~~~~
      

  2.   

    1、试试全局变量,如果全局变量不行,那试试给他们加事件时在取他们的值呀for(int i=0;i <ds.Tables[0].Rows.Count;i++) 
      { 
      checkbox ab=new checkbox(); 
      string str=ds.Tables[0].Rows [i][字段名].Tostring(); 
      ab.ID="ab"+i.Tostring(); 
      ab.Text=str; 
     // ab.事件名+=........
      this.Panel1.Controls.Add(ab);
    }
    然后在事件调用中用第一个参数CheckBox ab=(CheckBox)第一个参数参数名
      那可就可以取到某个发起事件的CheckBox了
      

  3.   

    如果我用 ArrayList 的话 那是放ID吗
      

  4.   

    在panel放个treeview,把treeview的复选属性打开,用treenode代替checkbox。
      

  5.   

    我要把checkbox的ID 放到Arraylist里 请问如何放进去 等到取checkbox的值的时候我去取Arraylist里的值 那又该如何取呢??在线等~~~~~~~~~~~~~~~
      

  6.   

    没有那么麻烦吧,LS几位!
    直接在panel.controls里循环就OK了.
      

  7.   

    //使用foreach循环遍历窗体中的所有控件  
     
      foreach(object o in this.Controls)   
      {   
              //判断该控件类型是否是TextBox   
              if(o is CheckBox)   
            {   
                      //如控件类型为CheckBox,为控件的Text属性赋值(遍历时使用的是object,所以要转换类型)   
                      ((TextBox)o).Text="OK";   
              }   
      }