这句
ImageButton img=(ImageButton)this.FindControl("ImageButton"+(i+1).ToString());
确认ImageButton"+(i+1)这个控件是否已经存在最好在此之前先做个存在判断.

解决方案 »

  1.   

    ImageButton img=(ImageButton)this.FindControl("ImageButton"+(i+1).ToString());这个写的不对
    建议你定义个输注将ImageButton添加进去
    List<string> aa=new List<string>();
    for(int i=0;i<80;i++)
    {
        aa.Add("ImageButton"+(i+1).tostring());
    }
    ImageButton img=(ImageButton)this.FindControl[arr[i];
      

  2.   

    没经过测试你看看我新手刚学习.net
      

  3.   

    网页太慢了,问题我已经解决了, 我imagebutton实际安排没有80个,但循环80次,所以有的查不到。谢谢各位帮忙。
     HasControls() 方法我也用错了,这里其实是不是判断是否有子控件,我没有完全理解该方法的意思。 
      

  4.   

    参考这个:    for (int i = 0; i < this.Controls.Count ; i++)
        {
            CheckBox cb = this.Controls["checkbox" + i] as CheckBox;//this.Controls[string] 要从控件集合中检索的控件的名称。
            if (cb != null)
            {
                Console.WriteLine("name :{0}   TabIndex :{1}", cb.Name, cb.TabIndex);
            }
        }