gpt4 book ai didi

asp.net - 如何在中继器页眉或页脚中查找控件

转载 作者:行者123 更新时间:2023-12-03 04:36:25 24 4
gpt4 key购买 nike

我想知道如何在 Asp.Net Repeater 控件的 HeaderTemplate 或 FooterTemplate 中找到控件。

我可以在 ItemDataBound 事件上访问它们,但我想知道如何在之后获取它们(例如检索页眉/页脚中输入的值)。

注意:我在找到答案后将这个问题发布在这里,只是为了记住它(也许其他人可能会发现这很有用)。

最佳答案

如评论中所述,这仅在您对中继器进行 DataBound 后才有效。

要在标题中查找控件:

lblControl = repeater1.Controls[0].Controls[0].FindControl("lblControl");

要在页脚中查找控件:

lblControl = repeater1.Controls[repeater1.Controls.Count - 1].Controls[0].FindControl("lblControl");
<小时/>

使用扩展方法

public static class RepeaterExtensionMethods
{
public static Control FindControlInHeader(this Repeater repeater, string controlName)
{
return repeater.Controls[0].Controls[0].FindControl(controlName);
}

public static Control FindControlInFooter(this Repeater repeater, string controlName)
{
return repeater.Controls[repeater.Controls.Count - 1].Controls[0].FindControl(controlName);
}
}

关于asp.net - 如何在中继器页眉或页脚中查找控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/701412/

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