简体   繁体   English

在 FormView 中找不到控件?

[英]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上使用适当的事件,例如ItemCreatedDataBound 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM