找不到FormView控件? [英] can't find control in FormView?

查看:202
本文介绍了找不到FormView控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要找到这个< A> 标记在 FormView控件控制居住,我需要删除这个标签取决于条件,但使用我找不到 FormView.FindControl

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

<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(),既不工作。
任何想法请??

I tried fvMediaIntro.FindControl() and fvMediaIntro.Row.FindControl(), neither worked. Any idea please??

推荐答案

的FindControl 将工作是即创建这些控件后,才将数据绑定到 FormView控件。所以,你需要使用的 FormView控件相应的事件这样的 ItemCreated 数据绑定。例如,

FindControl will work only after those controls are created i.e when data is bound to the FormView. So you need to use appropriate event on FormView such ItemCreated or DataBound. For example,

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

假设,你在的Page_Load 绑定或使用标记,你也可以使用 prerender 父页/控制事件安全办的FindControl

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.

这篇关于找不到FormView控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆