<div>
       新建 <asp:TextBox ID="TextBox1" runat="server" Width="26px"></asp:TextBox>个按钮
        <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
        <asp:Table ID="Table1" runat="server">
        </asp:Table>
    </div>
后台: protected void Button1_Click(object sender, EventArgs e)
    {
        int num = Convert.ToInt32(TextBox1.Text);
        int a = 1;
        while (a <= num)
        {
            TableRow tr = new TableRow();
            for (int i = 0; i < 3 & a <= num; i++)
            {
                TableCell tc = new TableCell();
                Button btn = new Button();
                btn.Text = a.ToString();
                tc.Controls.Add(btn);
                tr.Cells.Add(tc);
                a++;
                Table1.Rows.Add(tr);            }
        }    }

解决方案 »

  1.   

    动态添加textbox.
    <asp:Button ID="createbutton" runat="server" Text="批量创建"  
      onclick="createbutton_Click" />
    <asp:Table ID="HolderTable" runat="server"></asp:Table> protected override void OnLoad(EventArgs e)
      {
      CreateControl();
      }    protected void createbutton_Click(object sender, EventArgs e)
      {
      if (ViewState["CreateControl"] == null)
      {
      ViewState["CreateControl"] = true;
      CreateControl();
      }
      }    void CreateControl() {
      if (ViewState["CreateControl"]==null) return;   
      for (int x = 0; x < 20; x++)
      {
      TableRow row = new TableRow();
      for (int y = 0; y < 4; y++)
      {
      TableCell cell = new TableCell();  
      Button bt = new Button();
      bt.Text = string.Format(" x={0},y={1} ", x, y);
      cell.Controls.Add(bt);  
      row.Cells.Add(cell);
      }  
      HolderTable.Rows.Add(row);
      }
      }  
      

  2.   

    动态添加的控件,下次提交时不能从ViewState中恢复控件状态,需要将它们再次加入控件树,如梦的方法就是解决那个的,
    你的就没有解决