如何解决在FormView中找不到控件?
| 我需要找到此<a>
标记驻留在FormView
控件中,我需要根据条件删除此标记,但是我无法使用FormView.FindControl
方法找到它
<asp:UpdatePanel ID=\"upDiscipline\" runat=\"server\">
<ContentTemplate>
<asp:FormView ID=\"fvMediaIntro\" runat=\"server\">
<ItemTemplate>
<div class=\"clipControls\">
<a runat=\"server\" id=\"iNeedToFindThis\" href=\"#\">here</a>
</div>
</ItemTemplate>
</ContentTemplate>
</asp:UpdatePanel>
我尝试了fvMediaIntro.FindControl()
和fvMediaIntro.Row.FindControl()
,但都没有用。
有什么想法吗?
解决方法
只有在创建了这些控件之后,即将数据绑定到
FormView
时,6ѭ才起作用。因此,您需要在ѭ1上使用适当的事件,例如ItemCreated或DataBound
。例如,
protected void fvMediaIntro_ItemCreated(Object sender,EventArgs e)
{
var control = fvMediaIntro.Row.FindControl(\"iNeedToFindThis\") as HtmlAnchor;
}
假设您是在ѭ11中绑定或使用标记,您还可以安全地使用父页面/控件的prerender
事件来执行FindControl
。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。