如果不把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;
}
如果放到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;
}
解决方案 »
- 如何删除 VS2010 某工程 里面的所有注释?
- asp.net 实现页面下载
- 向memcache中写入时有必要lock吗?
- 数据库问题!!??
- CS0026: 关键字“this”在静态属性、静态方法或静态字段初始值设定项中无效 请高手来看看
- 怎样在DataGrid两行数据之间插入一个图片?效果如一个TD只显底部边框线
- 菜鸟求教
- 请提供一个生成treeview的xml例子?
- 请教一个SQL的问题
- 为什么在文件开头有了“<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="test.WebForm1" %>”
- 网站多分辨率问题
- 请问一个ImageButton 的问题,急
没见过这样赋值的
不知道这个保留的是什么数据
{
Session["tb"] = tb;
ViewState["count"] = 0;
}
每次回发的时候 tb肯定是null啊。
这里要给 tb= (DataTable) Session["tb"]
或者
tb= Session["tb"] as DataTable
但是根据你提供的代码 你这里的tb是<asp:table/>
当然为空了 建议先实例化一个DataTable