[英]can't find control in FormView?
I need find this <a>
tag resided in a FormView
control, I need to remove this a tag depending on the condition but I can't find it using FormView.FindControl
method我需要在
FormView
控件中找到此<a>
标记,我需要根据条件删除此标记,但我无法使用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>
I tried fvMediaIntro.FindControl()
and fvMediaIntro.Row.FindControl()
, neither worked.我尝试
fvMediaIntro.FindControl()
和fvMediaIntro.Row.FindControl()
,但都没有奏效。 Any idea please??请问有什么想法吗??
FindControl
will work only after those controls are created ie when data is bound to the FormView
. FindControl
仅在创建这些控件后才起作用,即当数据绑定到FormView
时。 So you need to use appropriate event on FormView
such ItemCreated or DataBound
.因此,您需要在
FormView
上使用适当的事件,例如ItemCreated或DataBound
。 For example,例如,
protected void fvMediaIntro_ItemCreated(Object sender, EventArgs e)
{
var control = fvMediaIntro.Row.FindControl("iNeedToFindThis") as HtmlAnchor;
}
Assuming, you are binding in page_load
or using mark-up, you can also use prerender
event of parent page/control safely to do FindControl
.假设您在
page_load
中绑定或使用标记,您还可以安全地使用父页面/控件的prerender
事件来执行FindControl
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.