動的に作成されたテーブルを、レンダリング後にフェッチできるビューに保存できます。
SqlConnection con =new SqlConnection(ConfigurationManager.ConnectionStrings["dbstring"].ConnectionString);
private int ctrName = 0;
Table tableName = null;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
tableName = new Table();
tableName.ID = "tableName";
Session["tableName"] = tableName;
ViewState["ctrName"] = ctrName;
}
ctrName = (Int32)ViewState["ctrName"];
tableName = (Table)Session["tableName"];
pnlName.Controls.Add(tableName);
}
private void GenerateName()
{
ctrName++;
TableRow row = new TableRow();
TableCell cell = new TableCell();
TextBox tb = new TextBox();
tb.ID = "Txt_Name" + ctrName;
tb.Width = 150;
cell.Controls.Add(tb);
row.Cells.Add(cell);
tableName.Rows.Add(row);
Session["tableName"] = tableName;
ViewState["ctrName"] = ctrName;
}
テーブルの詳細にアクセスするには:
tableName = (Table)Session["tableName"];