我的代码为读入: SqlConnection conn=new SqlConnection ("Data Source=.;Initial Catalog=zice;Trusted_Connection=True;");
ArrayList cc=new ArrayList();
......
for(int i=0;i<ds.Tables [0].Rows.Count ;i++)
{
CheckBox ab=new CheckBox() ;
string str=ds.Tables [0].Rows [i]["diji"].ToString ();
ab.ID ="ab"+i.ToString ();
ab.Text =str;
this.Panel1.Controls.Add (ab);
cc.Add(ab.ID );取出的时候为:for(int i=0;i<cc.Count ;i++)
this.TextBox1 .Text =((CheckBox)this.Panel1.FindControl(cc[i].ToString ())).Text;
可是为什么在运行的时候,还是只取到了一个checkbox的值呢???????????
ArrayList cc=new ArrayList();
......
for(int i=0;i<ds.Tables [0].Rows.Count ;i++)
{
CheckBox ab=new CheckBox() ;
string str=ds.Tables [0].Rows [i]["diji"].ToString ();
ab.ID ="ab"+i.ToString ();
ab.Text =str;
this.Panel1.Controls.Add (ab);
cc.Add(ab.ID );取出的时候为:for(int i=0;i<cc.Count ;i++)
this.TextBox1 .Text =((CheckBox)this.Panel1.FindControl(cc[i].ToString ())).Text;
可是为什么在运行的时候,还是只取到了一个checkbox的值呢???????????
直接到CheckBox的引用保存在ArrayList中,要用的时候就直接取出来转换一下,哪来那么多麻烦?cc.Add(ab);
....
CheckBox cb=cc[i] as CheckBox;
if(cb!=null)
{
this.TextBox1.Text=cb.Text;
...
}
{
CheckBox ab=cc[i] as CheckBox ;
if(ab!=null)
{
this.TextBox1 .Text =ab.Text ;
}
}
用了一楼的说法 textbox里无法显示出值
{ CheckBox ab=cc[i] as CheckBox ;
if(ab!=null)
{
this.TextBox1 .Text =ab.Text ;
}
else
{
.......
}
} 这段代码有问题吗 取出Arraylist里的checkbox值
....
CheckBox cb=cc[i] as CheckBox;
if(cb!=null)
{
this.TextBox1.Text=cb.Text;
...
}
用这个方法的前提是
SqlConnection conn=new SqlConnection ("Data Source=.;Initial Catalog=zice;Trusted_Connection=True;");
ArrayList cc=new ArrayList();
......
for(int i=0;i <ds.Tables [0].Rows.Count ;i++)
{
CheckBox ab=new CheckBox() ;
string str=ds.Tables [0].Rows [i]["diji"].ToString ();
ab.ID ="ab"+i.ToString ();
ab.Text =str;
this.Panel1.Controls.Add (ab); cc.Add(ab.ID ); //把这里改一来呀
cc.Add(ab);