DataGridItem.FindControl 找不到控件? (ASP.NET)
Label lbl = dgi.FindControl("LBL_MyLabel") as Label;
这在大多数情况下都有效,但有时在调用 FindControl 后 lbl 为 null。我想知道这是怎么发生的。它应该存在还是不存在?有什么想法吗?
标签定义如下:
<asp:Label ID="LBL_MyLabel" runat="server"></asp:Label>
谢谢:-)
Label lbl = dgi.FindControl("LBL_MyLabel") as Label;
This works most of the time, but sometimes lbl is null after FindControl was called. I am wondering how this could happen. It should either be there or not? Any ideas?
The label is defined like this:
<asp:Label ID="LBL_MyLabel" runat="server"></asp:Label>
Thanks :-)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
围绕
FindControl
调用的代码的更广泛上下文是什么?当迭代网格中的行(例如在RowDataBound
事件中)而不有条件地检查行类型是什么时,通常会遇到此错误:将其包装在该条件中将跳过页眉/页脚行,这会导致其中可能没有您的标签控件。
What's the broader context of the code around the call to
FindControl
? This error is commonly experienced when iterating through the rows in the grid (such as in theRowDataBound
event) without conditionally checking what the row type is:Wrapping it in that conditional will skip header/footer rows, which probably don't have your label control in them.