ASP.NET加载用户控件在直放站 [英] ASP.NET Loading a User Control in a Repeater
问题描述
我有一个加载我建立了一个自定义控件的实例Repeater控件。这个中继器看起来是这样的:
< ASP:直放站ID =myRepeater=服务器的OnLoad =myRepeater_Load>
<&HeaderTemplate中GT;
<表格边框=0的cellpadding =0CELLSPACING =0>
< / HeaderTemplate中> <&ItemTemplate中GT;
< TR>< TD><我:CustomControl ID =显示myControl=服务器
的OnLoad =myControl_Load/>
< / TD>< / TR>
< / ItemTemplate中> < FooterTemplate>
< /表>
< / FooterTemplate>
< / ASP:直放站>
我绑定到通过 myRepeater_Load
事件处理程序的中继。我的自定义控制,用于呈现Repeater中的一个项目。正因为如此,我想对 myControl_Load
事件处理过程中的自定义控件设置属性。但是,我不知道如何将 myControl_Load
活动期间访问当前项目。
有没有一种方法,我可以沿着当前项目通过或 myControl_Load
活动期间访问当前的项目吗?如果是这样,怎么样?
感谢您,
< ASP:直放站ID =rptrDemo=服务器OnItemDataBound =rptrDemo_ItemDataBound>
<&ItemTemplate中GT;
<演示:样本=服务器ID =sampleControl/>
< / ItemTemplate中>
< / ASP:直放站>
保护无效rptrDemo_ItemDataBound(对象发件人,RepeaterItemEventArgs E)
{
如果(e.Item.DataItem!= NULL)
{
SampleControl sampleControl =(SampleControl)e.Item.FindControl(sampleControl);
//做什么
}
}
I have a Repeater control that loads instances of a custom control I have built. This repeater looks like this:
<asp:Repeater ID="myRepeater" runat="server" OnLoad="myRepeater_Load">
<HeaderTemplate>
<table border="0" cellpadding="0" cellspacing="0">
</HeaderTemplate>
<ItemTemplate>
<tr><td><my:CustomControl ID="myControl" runat="server"
OnLoad="myControl_Load" />
</td></tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
I bind to the Repeater through the myRepeater_Load
event handler. My custom control is used to render an item within the Repeater. Because of this, I am trying to set properties on the custom control during the myControl_Load
event handler. However, I do not know how to access the current item during the myControl_Load
event.
Is there a way I can pass along the current item or access the current item during the myControl_Load
event? If so, how?
Thank you,
<asp:Repeater ID="rptrDemo" runat="server" OnItemDataBound="rptrDemo_ItemDataBound">
<ItemTemplate>
<demo:Sample runat="server" ID="sampleControl" />
</ItemTemplate>
</asp:Repeater>
protected void rptrDemo_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.DataItem != null)
{
SampleControl sampleControl = (SampleControl)e.Item.FindControl("sampleControl");
// do whatever
}
}
这篇关于ASP.NET加载用户控件在直放站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!