最近做一个问答系统,
大类别中的小类别同时在首页显示,
然后就用到repeater的嵌套。
-
Repeater.aspx:
<asp:Repeater ID="SortListRpt" runat="server" OnItemDataBound="SortListRpt_ItemDataBound">
<ItemTemplate>
<ul class="c1"><li>
<a href='SortList.aspx?id=<%# Eval("sid")%>' target="_blank"><%# Eval("sname")%></a>
<ul class="c2">
<asp:Repeater ID="SecondSortListRpt" runat="server">
<ItemTemplate>
<span><a href='SSortList.aspx?ssid=<%# Eval("ssid")%>' target="_blank"><%# Eval("ssname")%>
</a></span>
</ItemTemplate>
</asp:Repeater>
</ul>
</li></ul>
</ItemTemplate>
</asp:Repeater>
Repeater.aspx.cs
protected void SortListRpt_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
//判断里层repeater处于外层repeater的哪个位置( AlternatingItemTemplate,FooterTemplate,
//HeaderTemplate,,ItemTemplate,SeparatorTemplate)
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater rep = e.Item.FindControl("SecondSortListRpt") as Repeater;//找到里层的repeater对象
DataRowView rowv = (DataRowView)e.Item.DataItem;//找到分类Repeater关联的数据项
int typeid = Convert.ToInt32(rowv["sid"]); //获取填充子类的id
rep.DataSource =WenDa_bll.GetSecondSortListBySid(typeid);
rep.DataBind();
}
}
over。呵呵!