/ Published in: C#
Used to create a tabbed structure with accordions inside. NOTE: OnItemDataBound is called for each section, so you may want to filter on the proper section:
ListItemType lt = e.Item.ItemType;
if(lt == ListItemType.Item)....
ListItemType lt = e.Item.ItemType;
if(lt == ListItemType.Item)....
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
private void rptMonthSummary_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e) { ListItemType lt = e.Item.ItemType; if(lt == ListItemType.Item || lt == ListItemType.AlternatingItem) { DataRowView dv = e.Item.DataItem as DataRowView; if(dv != null) { Repeater nestedRepeater = e.Item.FindControl("rptDailySummary") as Repeater; if (nestedRepeater != null) { nestedRepeater.DataSource = dv.CreateChildView("yearMonth"); nestedRepeater.DataBind(); } } } } //here's a full code-behind that uses a strongly typed list of results to filter: protected void Page_Load(object sender, EventArgs e) { GetProducts(); } private void GetProducts() { { ProductList = (from p in context.Products orderby p.ProductType.Name, p.Name { ProductID = p.ProductID, ProductTypeID = p.ProductTypeID, Name = p.Name, Type = p.ProductType.Name, ShortDescription = p.ShortDescription }).ToList<ProductWithType>(); rptProductTypes.DataSource = ProductList; rptProductTypes.DataBind(); } } public void rptProductTypes_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e) { ListItemType lt = e.Item.ItemType; if (!(lt == ListItemType.Item || lt == ListItemType.AlternatingItem)) return; //only interested in the item/alternatingitem databind calls to this method, not the header, footer, etc. ProductWithType product = e.Item.DataItem as ProductWithType; //get the current row being databound Repeater rptProducts = e.Item.FindControl("rptProducts") as Repeater; //get the nested control rptProducts.DataSource = from p in ProductList where p.ProductTypeID == product.ProductTypeID select p; rptProducts.DataBind(); } } /// <summary> /// Used so result set above can be strongly typed. /// </summary> public class ProductWithType { public int ProductID { get; set; } public int ProductTypeID { get; set; } public string Name { get; set; } public string Type { get; set; } public string ShortDescription { get; set; } }
URL: http://idunno.org/archive/2004/10/30/145.aspx