在 Page_Init 上,我检查 Button1 是否被按下,如果是,我在面板中创建一系列 LiteralControl,称为 Panel1:
Panel1.Controls.Add(new LiteralControl("<table>"));
Panel1.Controls.Add(new LiteralControl("<tr>"));
Panel1.Controls.Add(new LiteralControl("<td>Header 1</td>"));
Panel1.Controls.Add(new LiteralControl("<td>Header 2</td>"));
Panel1.Controls.Add(new LiteralControl("<td>Header 3</td>"));
Panel1.Controls.Add(new LiteralControl("</tr>"));
Panel1.Controls.Add(new LiteralControl("<tr>"));
Panel1.Controls.Add(new LiteralControl("<td>Data 1</td>"));
Panel1.Controls.Add(new LiteralControl("<td>Data 2</td>"));
Panel1.Controls.Add(new LiteralControl("<td><input type=\"text\" name=\"txtCode3\"></td>"));
Panel1.Controls.Add(new LiteralControl("</tr>"));
Panel1.Controls.Add(new LiteralControl("</table>"));
我有第二个按钮,单击该按钮时,我想用所有表格单元格元素(或值)填充 NameValueCollection(或任何其他列表)。
我怎样才能做到这一点?我试过了:
protected void Button2_Click(object sender, EventArgs e)
{
NameValueCollection coll = Request.Form;
}
但这只会给我:
AllKeys:
[0] "_VIEWSTATE"
[1] "_EVENTVALIDATION"
[2] "Button2"
[3] "txtCode3"
如您所见,我无法获取所有单元格元素。我应该得到:
AllKeys:
[0] "_VIEWSTATE"
[1] "_EVENTVALIDATION"
[2] "Button2"
[3] Header 1
[4] Header 2
[5] Header 3
[6] Data 1
[7] Data 2
[3] "txtCode3"
谢谢你。