我在Page_load中创建控件,然后将创建的控件加载到指定的地方? protected void Page_Load(object sender, EventArgs e)
    {       
            Table t = new Table();
            t.ID = "table2";
            TableRow tr = new TableRow();           
            HtmlTextArea txt = new HtmlTextArea();
            txt.Cols = 20;
            txt.Rows = 5;
            txt.ID = "textarea1";    
            TableCell tc = new TableCell(); 
            tc.Controls.Add(txt);
            tr.Controls.Add(tc);
            t.Controls.Add(tr);            
            Panel1.Controls.Add(t);
            Literal htm = new Literal();
            htm.Text = "<hr /><br />";            
            Panel1.Controls.Add(htm);           
    }

解决方案 »

  1.   

    winfrom 行,webfrom嘛,我记得好几年前试过你这样的代码,结果失败了。
      

  2.   

    <asp:Table ID="HolderTable" runat="server"></asp:Table>
    for (int x = 0; x < 10; x++)
      {
      TableRow row = new TableRow();
      for (int y = 0; y < 10; y++)
      {
      TableCell cell = new TableCell();  
      Button bt = new Button();
      bt.Text = "";
      bt.Click += new EventHandler(bt_Click);
      cell.Controls.Add(bt);  
      row.Cells.Add(cell);
      }  
      HolderTable.Rows.Add(row);
      }
    void bt_Click(object sender, EventArgs e)
      {
      Button btn=sender as Button;
      }  是可以的
    添加到容器内
      

  3.   

    Refer:http://www.cnblogs.com/insus/articles/1632915.html