多个repeater嵌套使用
<ul>
<asp:Repeater ID="bClass" runat="server"
OnItemDataBound="bClassList">
<ItemTemplate>
<li>
<div><%#Eval("x_classname") %></div>
<asp:Repeater ID="bsClass" runat="server"
OnItemDataBound="bsClassList">
<HeaderTemplate><ul></HeaderTemplate>
<FooterTemplate></ul></FooterTemplate>
<ItemTemplate>
<li>
<div><%#Eval("x_classname") %></div>
<asp:Repeater ID="sClass" runat="server">
<HeaderTemplate><ul></HeaderTemplate>
<FooterTemplate></ul></FooterTemplate>
<ItemTemplate>
<li>
<div><%#Eval("x_classname") %></div>
</li>
</ItemTemplate>
</asp:Repeater>
</li>
</ItemTemplate>
</asp:Repeater>
</li>
</ItemTemplate>
</asp:Repeater>
</ul>
CS:
protected void Page_Load(object sender, EventArgs e)
{
if (Session["login"] == null)
{
Response.Redirect("login.aspx");
Response.End();
}
OleDbConnection conn = dbopen.getDB();
string bStr = "select id,x_classname,taxis,preid from
Table where preid=0 order by taxis asc,id asc";
OleDbDataAdapter rs = new OleDbDataAdapter(bStr,conn);
conn.Open();
DataSet rd = new DataSet();
rs.Fill(rd);
bClass.DataSource = rd;
bClass.DataBind();
conn.Close();
}
protected void bClassList(object
sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
string preid = ((DataRowView)e.Item.DataItem).Row["id"].ToString();//获得对应ID
Repeater bsClass = (Repeater)e.Item.FindControl("bsClass");//找到要绑定数据的Repeater
if (bsClass != null)
{
OleDbConnection sc = dbopen.getDB();
string ssql = "select id,x_classname,taxis,preid from Table where
preid="+preid+" order by taxis asc,id asc";
OleDbDataAdapter srs = new OleDbDataAdapter(ssql,sc);
sc.Open();
DataSet srd = new DataSet();
srs.Fill(srd);
bsClass.DataSource = srd;
bsClass.DataBind();
sc.Close();
}
}
}
protected void bsClassList(object
sender,RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
string preid = ((DataRowView)e.Item.DataItem).Row["id"].ToString();//获得对应ID
Repeater sClass =
(Repeater)e.Item.FindControl("sClass");//找到要绑定数据的Repeater
if (sClass != null)
{
OleDbConnection sc = dbopen.getDB();
string ssql = "select id,x_classname,taxis,preid from Table where
preid=" + preid + " order by taxis asc,id asc";
OleDbDataAdapter srs = new OleDbDataAdapter(ssql, sc);
sc.Open();
DataSet srd = new DataSet();
srs.Fill(srd);
sClass.DataSource = srd;
sClass.DataBind();
sc.Close();
}
}
}