Nesting using repeater in repeater

Source: Internet
Author: User
Tags eval
User controls that browse categories in a generic Web site are typically located on the left side of most asp.net pages, enabling users to quickly find products by category. Recently met a customer, because the product on his website is not many, so the request in the original category browsing based on the product added. A more convenient, and secondly lengthened the length of the left navigation bar to make the page more coordinated. The original category navigation bar is implemented by repeater, now need to add to each category of commodity information, so I thought of the original repeater nested repeater. The implementation interface is as follows:


Front Page section:
<asp:repeater id= "rptcategories" runat= "Server" >
<HeaderTemplate>
<table width= "100%" border= "0" cellspacing= "0" cellpadding= "0" >
</HeaderTemplate>
<ItemTemplate>
<!--category name-->
<tr><th><%# DataBinder.Eval (Container.DataItem, "TypeName")%></th></tr>
< product--> under the category of!--
<asp:repeater id= "rptproduct" runat= "Server" >
<ItemTemplate>
<tr><td><a href= ' productinfo.aspx? id=<%# DataBinder.Eval (Container.DataItem, "ID")%> ' ><%# DataBinder.Eval (Container.DataItem, " ProductName ")%></a></td></tr>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>

Background Code section (partial code):
When binding category name, the product under the binding category
private void Rptcategories_itemdatabound (object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
{
Bll. Products Products =new BLL. Products ();
if (E.item.itemtype = = ListItemType.Item | | E.item.itemtype = = ListItemType.AlternatingItem)
{
Repeater rptproduct = (Repeater) e.item.findcontrol ("rptproduct");
Find the data item that the taxonomy repeater associated with
DataRowView ROWV = (DataRowView) e.Item.DataItem;
Extract Category ID
int Categorieid = Convert.ToInt32 (rowv["ID"]);
According to the classification ID query the products under this category, and binding products repeater
Rptproduct.datasource = products. Getproductsbycategorieid (Categorieid);
Rptproduct.databind ();
}
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.