for (int i = 1; i < 10; i++)
        {
            ImageButton img = new ImageButton();
            img.ID = "caobin";
            img.PostBackUrl = "http://www.baidu.com";
            pl.Controls.Add(img);
        }当我加载一个ImageButton是可以成功的.加多个时却不行?请问前辈如何弄出来呢?谢谢了

解决方案 »

  1.   

    for (int i = 1; i < 10; i++)
            {
                ImageButton img = new ImageButton();
                img.ID = "caobin"+i.ToString();
                img.PostBackUrl = "http://www.baidu.com";
                pl.Controls.Add(img);
            }
      

  2.   

    给你段代码 ,这是我写的增加上传附件的,你看看吧,都差不多
     private void DynamicCreateAtt()
        {
            if (Convert.ToInt16(TextBox_AttNumber.Text) < 1) 
    //TextBox_AttNumber,用户输入上传附件个数
            {
                return;
            }        TextBox attDes = null;
            FileUpload att = null;        if (TABLE_ATT.Rows.Count > 2)
            {
                do
                {
                    TABLE_ATT.Rows.RemoveAt(TABLE_ATT.Rows.Count - 1);
                } while (TABLE_ATT.Rows.Count > 2);
            }        for (int i = 0; i < Convert.ToInt16(TextBox_AttNumber.Text); i++)
            {
                TABLE_ATT.Rows.Add(new HtmlTableRow());
                TABLE_ATT.Rows[TABLE_ATT.Rows.Count - 1].Cells.Add(new HtmlTableCell());
                TABLE_ATT.Rows[TABLE_ATT.Rows.Count - 1].Cells.Add(new HtmlTableCell());
                TABLE_ATT.Rows[TABLE_ATT.Rows.Count - 1].Cells.Add(new HtmlTableCell());
                TABLE_ATT.Rows[TABLE_ATT.Rows.Count - 1].Cells.Add(new HtmlTableCell());
                TABLE_ATT.Rows[TABLE_ATT.Rows.Count - 1].Align = "left";            TABLE_ATT.Rows[TABLE_ATT.Rows.Count - 1].Cells[0].InnerText = "附件: ";
                TABLE_ATT.Rows[TABLE_ATT.Rows.Count - 1].Cells[0].Width = "60px";            att = new FileUpload();
                att.ID = "FileUpload_Att" + i.ToString();
                att.Width = new Unit(300);            if (TABLE_ATT.FindControl(att.ID) == null)
                {
                    TABLE_ATT.Rows[TABLE_ATT.Rows.Count - 1].Cells[1].Controls.Add(att);
                    TABLE_ATT.Rows[TABLE_ATT.Rows.Count - 1].Cells[1].Align = "left";
                }            TABLE_ATT.Rows[TABLE_ATT.Rows.Count - 1].Cells[2].InnerText = "描述: ";
                TABLE_ATT.Rows[TABLE_ATT.Rows.Count - 1].Cells[2].Width = "60px";
                attDes = new TextBox();
                attDes.ID = "TextBox_AttDes" + i.ToString();
                attDes.Width = new Unit(180);
                attDes.MaxLength = 50;            if (TABLE_ATT.FindControl(attDes.ID) == null)
                {
                    TABLE_ATT.Rows[TABLE_ATT.Rows.Count - 1].Cells[3].Controls.Add(attDes);
                    TABLE_ATT.Rows[TABLE_ATT.Rows.Count - 1].Cells[3].Align = "left";
                }
            }
        }
      

  3.   

    自己解决:        ImageButton [] img = new ImageButton[10];
            for (int i = 1; i < 10; i++)
            {
                img[i] = new ImageButton();
                img[i].ID = i.ToString();
                pl.Controls.Add(img[i]);
            }