http://expert.csdn.net/Expert/topic/1945/1945697.xml?temp=.2097437

解决方案 »

  1.   

    使用如下代码并不能添加成功, 请继续:
    Button newbutton = new Button();
    newbutton.ID = "aaa";
    newbutton.Text = "AAA";
    Page.Controls.Add(newbutton);
      

  2.   

    protected System.Web.UI.WebControls.Table Table1;

    private void Page_Load(object sender, System.EventArgs e)
    {
    string[] n = new String[5];
    n[0] = "hehe";
    n[1] = "heihei";
    n[2] = "hengheng";
    n[3] = "kao";
    n[4] = "faint";
             for(int i=0;i<n.Length;i++)
    {
    Button bt = new Button();
    bt.Width = 100;
    bt.ID = n[i];
    bt.Text = n[i];
    //添加事件
    //bt.Attributes.Add("onclick","return NeedHelp();");
    int cellIndex = i%3;
    int rowIndex = i/3;
    if(cellIndex==0)
    {
    TableRow row = new TableRow();
    Table1.Rows.Add(row);
    }
    TableCell cell = new TableCell();
    TableRow currentRow = Table1.Rows[rowIndex];
    cell.Controls.Add(bt);
    currentRow.Cells.Add(cell);
    }
    }
      

  3.   

    我其实是想通过代码来控制对象的位置(left, top), 难道没能办法吗?