gpt4 book ai didi

c# - 在 FormView 中找不到控件?

转载 作者:行者123 更新时间:2023-11-30 14:17:23 24 4
gpt4 key购买 nike

我需要找到这个 <a>标签位于 FormView 中控制,我需要根据条件删除这个标签,但我无法使用 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>

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

最佳答案

FindControl 仅在创建这些控件后才起作用,即当数据绑定(bind)到 FormView 时。因此,您需要在 FormView 上使用适当的事件,例如 ItemCreatedDataBound。例如,

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

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

关于c# - 在 FormView 中找不到控件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6105634/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com