如何遍历页面所有Image控件,并将ID取出????代码怎么写?

解决方案 »

  1.   

     foreach (Image item in this.Page.Controls)
                {
                    Response.Write(item.ID+"-------------");
                }
      

  2.   

    foreach (Control ct in Page.Controls)
            {
                if (ct is Image)
                {
                    (ct as Image).ID;
                }
            }
      

  3.   


    ArrayList al  = new ArrayList();
    foreach (System.Windows.Forms.Control control in this.Controls)
    {
    if (control is System.Windows.Forms.Image)
    {
    System.Windows.Forms.Image img= (System.Windows.Forms.Image)control ;
    al.Add(img.ID);
    }

    for(int i=0;i<al.Count;i++)
    {
        Console.WriteLine(al[i].ToString());
    }
      

  4.   


    foreach (Control ct in Page.Controls)
            {
                if (ct is Image)
                {
                    this.Label1.Text =(ct as Image).ID;
                }
            }
    这样没有任何反应,也不报错。如何取出ID值赋值给Label1.Text 
      

  5.   


    void FindImage(Control c)
    {
        if(c is Image)
            Response.Write(c.ID);
        else if(c.Controls.Count > 0)
        {
            foreach(Control ctrl in c.Controls)
               FindImage(ctrl);
        }
    }
    然后调用:FindImage(this.Form);