<asp:Repeater ID="rpt1" runat="server" onitemdatabound="rpt1_ItemDataBound"> <HeaderTemplate> <table width=400 cellpadding=0 cellspacing=0></HeaderTemplate> <ItemTemplate><tr> <td><font color=black>後台。aspx.cs
protected void rpt1_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { Repeater rpt2 = (Repeater)e.Item.FindControl("rpt2"); //找到分類Repeater關聯的數據項 DataRowView rowv = (DataRowView)e.Item.DataItem; rpt2.ItemDataBound += new RepeaterItemEventHandler(rpt2_ItemDataBound); //最最重要的一句 //提取分類ID cid = Convert.ToInt32(rowv["ID"]); //根據分類ID查詢該分類下的產品,並綁定產品Repeater rpt2.DataSource = Pcategory.getP(cid);//數據綁定 rpt2.DataBind(); } } protected void rpt2_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { Repeater rpt3 = (Repeater)e.Item.FindControl("rpt3"); //找到分類Repeater關聯的數據項 DataRowView rowvv = (DataRowView)e.Item.DataItem; //提取分類ID cid2 = Convert.ToInt32(rowvv["ID"]); //根據分類ID查詢該分類下的產品,並綁定產品Repeater rpt3.DataSource = getrpt3(cid, cid2);//數據綁定 rpt3.DataBind(); } }
轉載自:http://www.aspnetjia.com