0
我正在动态创建一个包含文本框的表。我用下面的代码这样做:在ASP动态表中查找文本框控件
<asp:Table ID="SSGrid" runat="server"></asp:Table>
表正确填充,但是当我尝试访问更新后的值:
foreach (DataRow row in Score_Sheet.Rows) // Loop over the rows.
{
int rowIndex = Score_Sheet.Rows.IndexOf(row); // Not sure if i need this yet
Label label = new Label();
TextBox txt = new TextBox();
txt.Text = row["Value"].ToString();
txt.ID = row["Risk"].ToString();
label.Text = row["Risk"].ToString() + " = ";
rows = new TableRow();
cell = new TableCell();
cell.Controls.Add(label);
cell2 = new TableCell();
cell2.Controls.Add(txt);
rows.Controls.Add(cell);
rows.Controls.Add(cell2);
SSGrid.Controls.Add(rows);
}
这是通过该代码添加表到我的网页从表格的文本框中我得到一个空引用异常。
我发现控制代码是这样的:
TextBox txt_any = (TextBox)SSGrid.FindControl("ANY");
string anyany = txt_any.Text;
row1["Value"] = any;
我怎么能访问在该文本被更新的价值?
谢谢!
尝试重新绑定网格。 – prashant
您需要递归查找控件。 – Mairaj