如何在数据中继器的页脚模板中找到控件
ASPX:代码
;
我正在寻找的是能够在数据转发器的页脚中找到控件的源代码。当我进行数据绑定或在页面本身中查找控件时,我熟悉基本的“FindControl”,但是如何在数据转发器的页脚模板中找到控件?
这可能吗?如果是的话我怎样才能得到一些帮助,
再次感谢大家!
[更新]
我需要能够在数据绑定后执行此操作
ASPX : Code
<asp:repeater id="repeater" runat="server">
<headerTemplate></headerTemplate>
<itemtemplate></itemtemplate>
<footerTemplate> <asp:literal id=findme runate=server> </footerTeplate>
</asp:repeater>
What i am looking for is source code to be able to find the control within the footer of a data repeater. Im familiar with the basic "FindControl" when i do a databind or look for control within the page itself, but how can i find the control within a footer template of a data repeater?
Is this even possible? and if so how can i please get some assistance,
thanks again to all!!!
[update]
i need to be able to do this after the databind
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
有多种方法可以做到这一点,具体方法取决于您想要何时访问该控件。
如果您希望在 DataBind 期间使用它,只需在 Databound 项中执行以下操作即可。
如果您想在另一个时间点找到它,请访问转发器的 Item 集合,然后找到“Footer”项目,然后从该项目中您可以找到该控件。
更新
根据您添加的注释,您可以通过枚举项目集合来执行此操作,下面是一个 id 为 myRepeater 的转发器的示例。
There are a number of ways that you can do it, the exact way depends on when you want to get access to the control.
If you want it during DataBind, simply do the following inside the item Databound.
If you want to find it at another point in time, access the repeater's Item collection, then find the "Footer" item, and from that item, you can find the control.
Update
Based on your added note, you can do this by enumerating the item collection, below is an example with a repeater that has an id of myRepeater.
我认为您必须检查 ItemDataBound 事件处理程序中的 ListItemType。您可以检查页眉或页脚,然后使用 FindControl 方法访问该控件。
I think you have to check the ListItemType in an ItemDataBound event handler. You can check for Header or Footer and then use the FindControl method to access the control.
这会更好,因为 Items 集合不包含页眉和页脚
This will work better as Items collection doesn't contain header and footer
如果您需要在 DataBind 之后获取页脚(这是 OP 似乎想要的),那么您可以使用以下命令:
If you need to get the Footer after DataBind (which is what the OP appears to want) then you can use the following: