Beispiel #1
0
    protected void rptCategories_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            CategoryCount cc = (CategoryCount)e.Item.DataItem;

            HyperLink a = (HyperLink)e.Item.FindControl("parentCategory");

            if (cc.Count != 0)
            {
                a.NavigateUrl = "javascript:categoryselect('" + cc.ID + "')";
                a.Text        = cc.Name + " (" + cc.Count + ")";
            }
            else
            {
                a.Attributes.Add("style", "text-decoration: none;");
                a.Text = cc.Name;
            }

            List <CategoryCount> children = (List <CategoryCount>) cats.FindAll(
                delegate(CategoryCount c)
            {
                return(c.ParentId == cc.ID);
            });

            children.Sort(
                delegate(CategoryCount c, CategoryCount c1)
            {
                return(c.Name.CompareTo(c1.Name));
            });

            if (children != null && children.Count > 0)
            {
                Repeater c = (Repeater)e.Item.FindControl("rptCategoriesNested");
                c.ItemDataBound += new RepeaterItemEventHandler(rptCategoriesNested_ItemDataBound);
                c.DataSource     = children;
                c.DataBind();

                currentChildIndex = 0;
            }
        }
    }
Beispiel #2
0
    protected void Categories_List_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Category cat = (Category)e.Item.DataItem;

            var children = cats.FindAll(
                delegate(Category c) { return(c.ParentId == cat.Id); });
            if (children != null && children.Count > 0)
            {
                // reset the child index counter
                currentChildIndex = 0;

                Repeater c = (Repeater)e.Item.FindControl("NestedCategoriesList");
                c.ItemDataBound += NestedCategoriesList_ItemDataBound;
                c.DataSource     = children;
                c.DataBind();
            }
        }
    }