主题:[转帖]Repeater嵌套
申明 本帖出自:[url]http://www.cnntec.com/showtopic-1558.html[/url]
Repeater多层嵌套其实并不难。嵌套我就不说了,直接往<ItemTemplat>标记对里放就行了。
html代码
<asp:Repeater ID="Repeater1" runat="server" onitemdatabound="Repeater1_ItemDataBound">
<ItemTemplate>
<asp:Repeater ID="Repeater2" runat="server" OnItemCommand="Repeater2_ItemCommand" onitemdatabound="Repeater2_ItemDataBound">
<ItemTemplate>
<asp:Repeater ID="Repeater3" runat="server">
<ItemTemplate>
在此处继续嵌套,如果你愿意
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
以下为CS代码
protected void Page_Load(object sender, EventArgs e)
{
这里代码就不说了,非第一次加载的情况,绑定最外面的Repeater即Repeater[如果有必要]
}
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater repChild = (Repeater)e.Item.FindControl("Repeater2");
DataRowView dr = (DataRowView)e.Item.DataItem;
int PerentId = 通过dr获取父对象的索引,就是id唯一值(从数据库)
然后这里就把数据绑定到Repeater2上
}
}
protected void Repeater2_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater repChildmore = (Repeater)e.Item.FindControl("Repeater3");
同上
}
}
protected void Repeater3_ItemCommand(object source, RepeaterCommandEventArgs e)
{
........
Repeater repChildlot = (Repeater)e.Item.FindControl("........");
.......
当然如果子Repeater里还有别的控件你也可以通过e.Item.FindControl去实现
}
Repeater多层嵌套其实并不难。嵌套我就不说了,直接往<ItemTemplat>标记对里放就行了。
html代码
<asp:Repeater ID="Repeater1" runat="server" onitemdatabound="Repeater1_ItemDataBound">
<ItemTemplate>
<asp:Repeater ID="Repeater2" runat="server" OnItemCommand="Repeater2_ItemCommand" onitemdatabound="Repeater2_ItemDataBound">
<ItemTemplate>
<asp:Repeater ID="Repeater3" runat="server">
<ItemTemplate>
在此处继续嵌套,如果你愿意
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
以下为CS代码
protected void Page_Load(object sender, EventArgs e)
{
这里代码就不说了,非第一次加载的情况,绑定最外面的Repeater即Repeater[如果有必要]
}
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater repChild = (Repeater)e.Item.FindControl("Repeater2");
DataRowView dr = (DataRowView)e.Item.DataItem;
int PerentId = 通过dr获取父对象的索引,就是id唯一值(从数据库)
然后这里就把数据绑定到Repeater2上
}
}
protected void Repeater2_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater repChildmore = (Repeater)e.Item.FindControl("Repeater3");
同上
}
}
protected void Repeater3_ItemCommand(object source, RepeaterCommandEventArgs e)
{
........
Repeater repChildlot = (Repeater)e.Item.FindControl("........");
.......
当然如果子Repeater里还有别的控件你也可以通过e.Item.FindControl去实现
}