在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
。