如果不把table放到session中就能显示,
如果放到session中就不显示了,但是每次点击按钮时session中的table的rows的count属性都会增加。
这是怎么回事啊?<asp:table id="tb" runat="server" CellPadding="1" CellSpacing="1" BorderWidth="1"></asp:table>
protected void Page_Load(object sender, EventArgs e)
    {       
        if (!IsPostBack)
        { 
            Session["tb"] = tb;
            ViewState["count"] = 0;
        }       
    }
//点击按钮时添加一行一列
protected void Button4_Click(object sender, EventArgs e)
    {        
        TableRow tr = new TableRow();
        TableCell ta = new TableCell();
        TextBox t = new TextBox();
        int count = Convert.ToInt32(ViewState["count"]);
        t.ID = "txt" + count.ToString();
        count++;
        ViewState["count"] = count;
        t.Text = "a";
        ta.Controls.Add(t);
        tr.Cells.Add(ta);
        tb = Session["tb"] as Table;
        tb.Rows.Add(tr);
        Session["tb"] = tb;
    }

解决方案 »

  1.   

    Session["tb"] = tb;
    没见过这样赋值的
    不知道这个保留的是什么数据
      

  2.   

    那应该怎么把table保存下来啊
      

  3.   

    if (!IsPostBack)
            { 
                Session["tb"] = tb;
                ViewState["count"] = 0;
            }       
    每次回发的时候 tb肯定是null啊。
    这里要给 tb= (DataTable) Session["tb"] 
      

  4.   

    tb= (DataTable) Session["tb"] 
    或者
    tb= Session["tb"] as  DataTable 
      

  5.   

    老大  我想你是想把DataTable赋给Session吧
    但是根据你提供的代码   你这里的tb是<asp:table/>
    当然为空了   建议先实例化一个DataTable