本帖最后由 yuandongze 于 2010-04-14 11:05:21 编辑

解决方案 »

  1.   

    你每次提交都刷新页面  页面又重新加载了次所以每次都只能加一个
    定义一个静态变量存储 TableCell tc = new TableCell();
    static List<TableCell> listc = new static List<TableCell>();
    点击  Button1_Click时先将 tc 加到 listc里
    之后再从 listc循环里读取添加到页面
      

  2.   

    点击button的时候引发page_load 你之前的生成的肯定没有了 可以考虑用js生成
      

  3.   

    这样做 生成是没有问题了, 但是点击另一个 Button想要 取值的时候,还是重新刷空,大哥在给想个办法吧
      

  4.   

    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Collections.Generic;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;public partial class development : System.Web.UI.Page
    {
        static List<TableCell> listc = new List<TableCell>();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) {
                ViewState["i"] = 0;
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            TableCell tc=new TableCell();
            tc.ID="tc" + ViewState["i"].ToString();
            TextBox tx = new TextBox();
            tx.ID = "tx" + ViewState["i"].ToString();
            tx.Text = "Hello";
            tc.Controls.Add(tx);
            listc.Add(tc);
                    for (int j = 0; j < listc.Count; j++)
    {
      TableRow tr=new TableRow();
                    tr.ID="tr"+ViewState["i"].ToString();
                    tr.Cells.Add(listc[j]);
                    t1.Controls.Add(tr);
    }
                //TableCell tc = new TableCell();
                //tc.ID = "tc" + ViewState["i"].ToString();            //TextBox tx = new TextBox();
                //tx.ID = "tx" + ViewState["i"].ToString();
                //tx.Text = "Hello";
                //tc.Controls.Add(tx);            //tc.Width = Unit.Pixel(100);            //TableRow tr = new TableRow();
                //tr.ID = "tr" + ViewState["i"].ToString();
                //tr.Controls.Add(tc);            //t1.Rows.Add(tr);
            }
        protected void Button2_Click(object sender, EventArgs e)
        {
            for (int j = 0; j < Convert.ToInt32(ViewState["i"]); j++)
            {
                TextBox2.Text += (t1.FindControl("tx" + j) as TextBox).Text;
            }
        }
    }
      

  5.   

    static List<TableCell> listc;
      protected void Page_Load(object sender, EventArgs e)
      {
      if (!IsPostBack) {
      ViewState["i"] = 0;
     listc = new List<TableCell>();  }
      }
    这样试试