绑定控件内的 ASP.Net 数据绑定
我今天对 ASP.Net 数据绑定有点感兴趣,基本上我有两个嵌套控件,以及一个带有我希望绑定的自己内部集合的对象集合...
所以,假设我正在使用两个中继器,例如这个->
<asp:Repeater ID="Repeater1">
<ItemTemplate>
<asp:Label runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "HeaderText")%>'>
</asp:Label>
<asp:Repeater ID="Repeater2">
<asp:Label runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "DetailText")%>'>
</asp:Label>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
我的对象看起来像这样:
public class parent
{
public string HeaderText {get;set;}
public List<child> children {get;set;}
}
public class child
{
public string DetailText {get;set;}
}
如何绑定内部中继器?我猜我需要设置 &将“Repeater2”的数据源绑定在aspx中的某个位置作为“parent”的“children”属性?
有人能指出我正确的方向吗?
谢谢
I'm having a littl fun with ASP.Net data binding today, basically I have two nested controls, and an collection of objects with their own internal collections which I wish to bind...
So, say I'm using two repeaters like this ->
<asp:Repeater ID="Repeater1">
<ItemTemplate>
<asp:Label runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "HeaderText")%>'>
</asp:Label>
<asp:Repeater ID="Repeater2">
<asp:Label runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "DetailText")%>'>
</asp:Label>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
And my objects look like this:
public class parent
{
public string HeaderText {get;set;}
public List<child> children {get;set;}
}
public class child
{
public string DetailText {get;set;}
}
How do I bind the inner repeater? I'm guessing that I need to set & bind the datasource of 'Repeater2' somewhere in the aspx to be the 'children' property of 'parent'?
Can someone point me in the right direction?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在主转发器
ItemDataBound
事件中绑定嵌套转发器。http://msdn.microsoft.com /en-us/library/system.web.ui.webcontrols.repeater.itemdatabound.aspx
在这里您可以找到控件 (
FindControl
) 并绑定到它。它会是这样的:
Bind the nested repeater in the main repeater
ItemDataBound
event.http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater.itemdatabound.aspx
Here you can find the control (
FindControl
) and bind to it.It would be something like:
您可以在外部转发器的
ItemDatabound
事件中绑定内部转发器:如果需要,使用
ListView
或DataList
可能会更容易使用外部数据绑定控件中的数据来绑定内部数据绑定控件,因为您可以指定数据键。隐藏代码:
You would bind the inner repeater in the
ItemDatabound
event of the outer repeater:It might be easier to use a
ListView
orDataList
if you need to use data from the outer databound control to bind the inner databound control, because you can specify datakeys.Code-behind: