Nesting using repeater in repeater

Source: Internet
Author: User
Nested in repeater using repeater.

This example is written using Vs.net (C #). From admin10000.com

Background CS Code

        protected void Page_Load (object sender, EventArgs e) {if (!                Page.IsPostBack) {this.dtcategory = Getcategorytable ();                This.dtproduct = Getproducttable ();                Rptcategorylist.datasource = dtcategory;            Rptcategorylist.databind ();            }}//Prepare a classification table for DataTable Getcategorytable () {datatable dt = new DataTable (); Dt.            Columns.Add ("CategoryId", typeof (int)); Dt.            Columns.Add ("Categorytitle", typeof (String)); for (int i = 1; I <= 3; i++) {DataRow row = dt.                NewRow ();                row["CategoryId"] = i;                row["Categorytitle"] = "category name" + i + ""; Dt.            Rows.Add (row);        } return DT;            }//Prepare a Product Table DataTable Getproducttable () {datatable dt = new DataTable (); Dt. Columns.Add ("ProductTitle", typeof (String)); Dt.            Columns.Add ("CategoryId", typeof (int)); for (int i = 1; I <= 9; i++) {DataRow row = dt.                NewRow ();                row["ProductTitle"] = "Product Name" + i + "";                if (i > 6) row["CategoryId"] = 3;                else if (i > 3) row["CategoryId"] = 2;                else row["CategoryId"] = 1; Dt.            Rows.Add (row);        } return DT; }//Get product for a category DataTable getproducttable (int categoryId) {DataView DV = this.dtProduct.De            Faultview; Dv.            RowFilter = "Categoryid=" + CategoryId + ""; Return DV.        ToTable (); } protected void Rptcategorylist_itemdatabound (object sender, RepeaterItemEventArgs e) {if (e.it Em. ItemType = = ListItemType.AlternatingItem | |                E.item.itemtype = = ListItemType.Item) {DataRowView DRV = (DataRowView) e.Item.DataItem; Literal Ltltitle = (Literal) e.iteM.findcontrol ("Ltltitle"); Ltltitle.text = drv["Categorytitle"].                ToString ();                Repeater rptproductlist = (Repeater) e.item.findcontrol ("Rptproductlist");                Rptproductlist.datasource = getproducttable (Convert.ToInt32 (drv["CategoryId"]));            Rptproductlist.databind ();            }} protected void Rptproductlist_itemdatabound (object sender, RepeaterItemEventArgs e) { if (E.item.itemtype = = ListItemType.AlternatingItem | | e.item.itemtype = = listitemtype.item) {D                Atarowview DRV = (DataRowView) e.Item.DataItem;                Literal Ltltitle = (Literal) e.item.findcontrol ("Ltltitle"); Ltltitle.text = drv["ProductTitle"].            ToString (); }        }

Foreground aspx code

  <form id= "Form1" runat= "Server" > <p> <asp:repeater id= "rptcategorylist" runat= "Server" Onitemda                    tabound= "Rptcategorylist_itemdatabound" > <ItemTemplate> <p class= "ListBox" > <p class= "title" > <asp:literal id= "ltltitle" runat= "Server" ></asp:lite                            ral></p> <p class= "Content" > <ul>                                <asp:repeater id= "rptproductlist" runat= "Server" onitemdatabound= "Rptproductlist_itemdatabound" > <ItemTemplate> <li> &L                                T;asp:literal id= "Ltltitle" runat= "Server" ></asp:Literal> </li> </ItemTemplate> </asp:Repeater> </                  Ul>  </p> </p> </ItemTemplate> </asp:Repeater> </p> < /form>

Download code example: Pagedemo.rar

Related documents: pagination implementation of the Repeater control Repeater control implements edit, update, delete operations repeater multiple-line interval display separator method

Related Article

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.