在FormView中找不到控件?

我需要找到这个标签驻留在FormView控件中,我需要根据条件删除这个标签,但我无法使用FormView.FindControl方法找到它

         

我试过fvMediaIntro.FindControl()fvMediaIntro.Row.FindControl() ,但都没有用。 有什么想法吗?

只有在创建了这些控件之后,即将数据绑定到FormView时, FindControl才会起作用。 因此,您需要在FormView上使用适当的事件,例如ItemCreated或DataBound 。 例如,

 protected void fvMediaIntro_ItemCreated(Object sender, EventArgs e) { var control = fvMediaIntro.Row.FindControl("iNeedToFindThis") as HtmlAnchor; } 

假设您在page_load中绑定或使用标记,您还可以安全地使用父页面/控件的prerender事件来执行FindControl