本文介绍了在C#中嵌套的中继器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好我一定要显示分层信息(其中有四个级别),中继器内。为此,我决定使用嵌套Repeater控件。
我发现这篇文章在MSDN上,这展示了如何使用嵌套中继器的信息,两个层次。
可有人请帮助我,这扩大到四个层次?
样本code将大大appriciated。谢谢。
Hi I have to display hierarchical information (which has four levels) within a repeater. For this I decided to use the nested repeater control.I found this article on MSDN, http://support.microsoft.com/kb/306154 which shows how to use nested repeaters for two levels of information.Can someone please help me extend this to four levels?A sample code would be much appriciated. Thank you.
推荐答案
HTML code:
<asp:Repeater ID="Repeater1" runat="server"
onitemdatabound="Repeater1_ItemDataBound">
<ItemTemplate>
<h1>
Repeater 1</h1>
<asp:Repeater ID="Repeater2" runat="server" onitemdatabound="Repeater2_ItemDataBound">
<ItemTemplate>
<h1>
Repeater 2
</h1>
<asp:Repeater ID="Repeater3" runat="server" onitemdatabound="Repeater3_ItemDataBound">
<ItemTemplate>
<h1>
Repeater 3
</h1>
<asp:Repeater ID="Repeater4" runat="server" onitemdatabound="Repeater4_ItemDataBound">
<ItemTemplate>
<h1>
Repeater 4
</h1>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
C#code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt1 = new DataTable();
//Need to assign the Data in datatable
Repeater1.DataSource = dt1;
Repeater1.DataBind();
}
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater Repeater2 = (Repeater)(e.Item.FindControl("Repeater2"));
DataTable dt2 = new DataTable();
//Need to assign the Data in datatable
Repeater2.DataSource = dt2;
Repeater2.DataBind();
}
}
protected void Repeater2_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater Repeater3 = (Repeater)(e.Item.FindControl("Repeater3"));
DataTable dt3 = new DataTable();
//Need to assign the Data in datatable
Repeater3.DataSource = dt3;
Repeater3.DataBind();
}
}
protected void Repeater3_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater Repeater4 = (Repeater)(e.Item.FindControl("Repeater4"));
DataTable dt4 = new DataTable();
//Need to assign the Data in datatable
Repeater4.DataSource = dt4;
Repeater4.DataBind();
}
}
}
这篇关于在C#中嵌套的中继器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!