【发布时间】:2014-11-23 07:41:27
【问题描述】:
当我加载页面时,我会发送表格的行数:
protected void Page_Load(object sender, EventArgs e)
{
string numFilas = Request.QueryString["filas"];
tblAdd.Visible = true;
for (int i = 0; i < int.Parse(numFilas); i++)
{
TableRow NewRow1 = new TableRow();
TableCell NewCell1 = new TableCell();
TableCell NewCell2 = new TableCell();
TextBox txtBox1 = new TextBox();
txtBox1.Width = 200;
TextBox txtBox2 = new TextBox();
txtBox2.Width = 200;
// adding lebel into cell
NewCell1.Controls.Add(txtBox1);
NewCell2.Controls.Add(txtBox2);
// adding cells to row
NewRow1.Cells.Add(NewCell1);
NewRow1.Cells.Add(NewCell2);
tblAdd.Rows.Add(NewRow1);
}
}
现在,当我点击提交时,我想检索表格内文本框的数据,我能够做到的是:
public void submit(Object sender, EventArgs e)
{
for (Int32 i = 0; i < tblAdd.Rows.Count; i++)
{
TableRow dr = tblAdd.Rows[i];
TableCell hhh = dr.Cells[0];
String textCell = hhh.Text();
}
}
但是,单元格中的文本是空的,因为用户写的文本在文本框中,我不知道如何获取它。
【问题讨论】:
-
考虑阅读任何关于“从动态添加的控件获取值”的文章/问题,例如stackoverflow.com/questions/17581616/…。旁注:请检查“asp-classic”(.Net 框架之前)是否是正确的标签。