//前台代码
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<div>
<asp:Repeater id="rptCategories" runat="server"
onitemdatabound="rptCategories_ItemDataBound">
<HeaderTemplate>
<table border="0" cellspacing="0" cellpadding="0">
</HeaderTemplate>
<ItemTemplate>
<!--分类名称-->
<tr><th><%# DataBinder.Eval(Container.DataItem, "TypeName") %></th></tr>
<!--分类下的产品-->
<asp:Repeater id="rptProduct" runat="server">
<ItemTemplate>
<tr><td><a href='ProductInfo.aspx?Id=<%# DataBinder.Eval(Container.DataItem, "ID") %>'><%# DataBinder.Eval(Container.DataItem, "ProduceName")%></a></td></tr>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</div>
</div>
</form>
</body>
</html>
//后台代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
namespace WebApplicationUI
{
public partial class Repeater嵌套Repeater实现页面导航 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
bindRepeater();//绑定第一级父节点
}
{
public partial class Repeater嵌套Repeater实现页面导航 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
bindRepeater();//绑定第一级父节点
}
//绑定主Repeater
void bindRepeater()
{
BLL.ProductBll procduct=new BLL.ProductBll();
rptCategories.DataSource = procduct.getProduct();
rptCategories.DataBind();
}
rptCategories.DataBind();
}
//在绑定分类品名时,绑定分类下的产品
protected void rptCategories_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
BLL.ProductBll products = new BLL.ProductBll();
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater rptProduct = (Repeater)e.Item.FindControl("rptProduct");
//找到分类Repeater关联的数据项
DataRowView row = (DataRowView)e.Item.DataItem;
//提取分类ID
int CategorieId = Convert.ToInt32(row["ID"]);
//根据分类ID查询该分类下的产品,并绑定产品Repeater
rptProduct.DataSource = products.getProduceById(CategorieId);
rptProduct.DataBind();
}
}
}
}
}
使用ASP.NET Core实现多级分类导航的电子商务网站
2047

被折叠的 条评论
为什么被折叠?



