我已经使用Asp.net和c#创建了一个动态表。现在,我想将此动态创建的表存储在会话中,该怎么办?
我是Asp.Net和编程的新手。
谢谢。
public partial class WebForm1 : System.Web.UI.Page
{
}
protected void Page_Load(object sender, EventArgs e)
{
}
public void CreateRuntime_Table()
{
int tblRows = int.Parse(txtrow.Text);
int tblCols = int.Parse(txtcol.Text);
Table tbl = new Table();
tbl.BorderWidth = 3;
tbl.BorderStyle = BorderStyle.Solid;
tbl.ID = "myTable";
for (int i = 1; i <= tblRows; i++)
{
TableRow tr = new TableRow();
for (int j = 1; j <= tblCols; j++)
{
TableCell tc = new TableCell();
TextBox txtbox = new TextBox();
txtbox.Text = "Test Row:" + i + "Test Col:" + " " + j;
//Add the control to the table cell
tc.Controls.Add(txtbox);
tr.Controls.Add(tc);
}
tbl.Rows.Add(tr);
}
form1.Controls.Add(tbl);
}
protected void Unnamed_Click(object sender, EventArgs e)
{
CreateRuntime_Table();
}
答案 0 :(得分:2)
要将表存储在会话中,请执行以下操作:
Table tbl = new Table();
...
Session["myTable"] = tbl;
要从会话中获取表,请执行以下操作:
Table getTableFromSession = (Table)Session["myTable"];