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