查找控制表单元格

发布于 2024-09-04 00:30:58 字数 367 浏览 3 评论 0原文

我想通过代码中的字符串 ID 来引用表格单元格,例如 FindControl("tdAnswer_a") 因为我正在操作字符串 ID 名称。 ASPX 代码如下所示:

<table>...<td ID="tdAnswer_a" runat="server" visible="true">

但 FindControl 无法找到表格单元格。当我在代码隐藏中通过这样的 ID 引用它时: tdAnswer_a.Visible = true; ,它没有问题。 (这不是中继器或网格视图的一部分)。

如何通过字符串 ID 名称 FindControl 我的表格单元格?

I want to reference a table cell via it's string ID in my code like this FindControl("tdAnswer_a") because I am manipulating string ID names. The ASPX code looks like this :

<table>...<td ID="tdAnswer_a" runat="server" visible="true">

But FindControl is not able to find the table cell. When I reference it by ID like this : tdAnswer_a.Visible = true; in my codebehind, it has no problems. (This is not part of a repeater or gridview).

How can I FindControl my table cells via string ID names?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时常饿 2024-09-11 00:30:58

FindControl 不是递归函数。如果它们位于其他容器控件内,并且您在 Page 对象上调用 FindControl,则不会找到它们。

您需要在直接容器上调用FindControl,或者编写一个递归FindControl 函数。

您可以看到 我旧答案中的递归 FindControl

FindControl is not a recursive function. If they are inside of some other container control, and you call FindControl on the Page object, then they won't be found.

You need to call FindControl on the direct container, or else write a recursive FindControl function.

You can see a version of a recursive FindControl in my old answer here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文