我正在尝试在动态 HTML 表中找到动态控件。我有以下内容:
System.Web.UI.HtmlControls.HtmlTableRow TR = null;
System.Web.UI.HtmlControls.HtmlTableCell TD1 = null;
System.Web.UI.HtmlControls.HtmlTableCell TD2 = null;
System.Web.UI.HtmlControls.HtmlTableCell TD3 = null;
System.Web.UI.HtmlControls.HtmlTableCell TD4 = null;
System.Web.UI.HtmlControls.HtmlTableCell TD5 = null;
System.Web.UI.HtmlControls.HtmlTableCell TD6 = null;
// Database stuff
int i = 1;
while (objRdr.Read())
{
TR = new System.Web.UI.HtmlControls.HtmlTableRow();
TD1 = new System.Web.UI.HtmlControls.HtmlTableCell();
TD2 = new System.Web.UI.HtmlControls.HtmlTableCell();
TD3 = new System.Web.UI.HtmlControls.HtmlTableCell();
TD4 = new System.Web.UI.HtmlControls.HtmlTableCell();
TD5 = new System.Web.UI.HtmlControls.HtmlTableCell();
TD6 = new System.Web.UI.HtmlControls.HtmlTableCell();
// ASP code maybe wrong, but its to give you the ID.
TD1.InnerHtml = "<asp:RadioButton runat='server' ID='radApprove"+i.ToString()+"' Value='Approve' />";
TD2.InnerText = HttpUtility.HtmlEncode(objRdr[1].ToString());
TD3.InnerText = HttpUtility.HtmlEncode(objRdr[6].ToString());
TD4.InnerText = HttpUtility.HtmlEncode(objRdr[2].ToString());
TD5.InnerText = HttpUtility.HtmlEncode(objRdr[10].ToString());
TD6.InnerText = HttpUtility.HtmlEncode(objRdr[8].ToString());
TR.Cells.Add(TD1);
TR.Cells.Add(TD2);
TR.Cells.Add(TD3);
TR.Cells.Add(TD4);
TR.Cells.Add(TD5);
TR.Cells.Add(TD6);
tblOrderItems.Rows.Add(TR);
TR = null;
TD1 = null;
TD2 = null;
TD3 = null;
TD4 = null;
TD5 = null;
TD6 = null;
i++;
}
现在,当我尝试从 Cells 中获取数据时,它失败了。我努力了:
this.FindControl("radApprove1");
但这会返回一个null
. 我也尝试迭代表中的行,但它只表示 1 行,即 Header。这段代码是从 中调用的Page_Load
,所以我想我可以得到这些控件。当我在呈现页面后查看其 HTML 源代码时,我可以看到它们已正确呈现。有任何想法吗?