我的代码是这样的我用了个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的值呢???
{
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的值呢???
{
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了
直接在panel.controls里循环就OK了.
foreach(object o in this.Controls)
{
//判断该控件类型是否是TextBox
if(o is CheckBox)
{
//如控件类型为CheckBox,为控件的Text属性赋值(遍历时使用的是object,所以要转换类型)
((TextBox)o).Text="OK";
}
}