An example of nested repeater in repeater

Source: Internet
Author: User
Tags prepare

  In some special cases it is necessary to use repeater in Repeater, here is a good example, interested friends can refer to the following

The code is as follows: protected void Page_Load (object sender, EventArgs e)   {  if (! Page.IsPostBack)   {  this.dtcategory = getcategorytable ();  this.dtproduct = getproducttable ();  Rptcategorylist.datasource = dtcategory;  rptcategorylist.databind (); } } //Prepare a list   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"] = "Classification 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 a category of products   DataTable getproducttable (int CategoryID)   {  DataView dv = this.dtproduct.defaultview;  dv. RowFilter = "Categoryid=" + CategoryID + "";  return DV. ToTable (); }  protected void Rptcategorylist_itemdatabound (object sender, RepeaterItemEventArgs e)   {& nbsp if (E.item.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)   {& nbsp if (E.item.itemtype = = ListItemType.AlternatingItem | | e.item.itemtype = listitemtype.item)   {  DataRowView DRV = (DataRowView) e.item.dataitem;  Literal ltltitle = (Literal) e.item.findcontrol ("Ltltitle");  Ltltitle.text = drv["ProductTitle"]. ToString (); } }    foreground aspx code   code is as follows: <</code>form id= "Form1" runat= "Server" >   <</CODE>div>  <</code>asp:repeater id= "rptcategorylist" runat= "Server" Onitemdatabound= "Rptcategorylist_itemdatabound" >  <</CODE>ItemTemplate>  <</code >div class= "ListBox" >  <</code>div class= "title" >  <</code>asp:literal id= " Ltltitle "runat=" Server ></</CODE>asp:Literal></</CODE>div>  <</CODE> div class= "Content" >  <</CODE>ul>  <</code>asp:repeater id= "rptproductlist" runat= "Server" onitemdatabound= "Rptproductlist_itemdatabound" >   <</CODE>ItemTemplate>  <</CODE>li>  <</code>asp:literal id= " Ltltitle "runat=" Server ></</CODE>asp:Literal>  </</CODE>li>  </</code >ItemTemplate>  </</CODE>asp:Repeater>  </</CODE>ul>  </</code >div>  </</CODE>div>  </</CODE>ItemTemplate>  </</code>asp: repeat</</code>div>  </</CODE>form> 

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.