How To Embed A UserControl In A Repeater

Page ASPX

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
    CodeBehind="ControlInRepeater.aspx.cs" Inherits="com.dereksandbox.ui.Pages.ControlInRepeater" %>

<%@ Register Src="../Controls/EmbeddedControl.ascx" TagName="EmbeddedControl" TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <asp:Repeater ID="Repeater1" runat="server" 
        onitemdatabound="Repeater1_ItemDataBound">
        <ItemTemplate>
            <uc1:EmbeddedControl ID="EmbeddedControl1" runat="server" />
        </ItemTemplate>
    </asp:Repeater>
</asp:Content>

Page Code Behind

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using com.dereksandbox.bl.ServiceManagers;
using com.dereksandbox.bl.Entities;
using com.dereksandbox.ui.Controls;

namespace com.dereksandbox.ui.Pages
{
    public partial class ControlInRepeater : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Repeater1.DataSource = PersonServiceManager.getPeople();
            Repeater1.DataBind();
        }

        protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            
            
            // This event is fired each time a new Person control is created in the repeater

            EmbeddedControl ctrl = (EmbeddedControl)e.Item.FindControl("EmbeddedControl1");
            ctrl.Person = (PersonEntity)e.Item.DataItem;           
           

        }
    }
}

Control ASCX

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="EmbeddedControl.ascx.cs"
    Inherits="com.dereksandbox.ui.Controls.EmbeddedControl" %>
<asp:Label ID="lblName" runat="server" Text="lblName"></asp:Label>
<asp:Label ID="lblWeight" runat="server" Text="lblAge"></asp:Label>
<br />

Control CodeBehind

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using com.dereksandbox.bl.Entities;

namespace com.dereksandbox.ui.Controls
{
    public partial class EmbeddedControl : System.Web.UI.UserControl
    {
        public PersonEntity Person { get; set; }


        protected void Page_Load(object sender, EventArgs e)
        {
            lblName.Text = Person.Name;
            lblWeight.Text = Person.Weight.ToString();
          
        }

      
    }
}

Bind ASP.NET Repeater to List of Enum’s

C#

            //  instantiate List of enum and add to it
            List<InvestorEmailAlertType> subscriptions = new List<InvestorEmailAlertType>();
            subscriptions.Add(InvestorEmailAlertType.AllCorporateNewsReleases);
            subscriptions.Add(InvestorEmailAlertType.FinancialNewsReleasesOnly);

            // Bind list to repeater
            RepeaterSubscriptions.DataSource = subscriptions;
            RepeaterSubscriptions.DataBind();

ASP.NET

            <asp:Repeater ID="RepeaterSubscriptions" runat="server">
                <ItemTemplate>
                    <ul>
                        <li>
                            <%# Container.DataItem %>
                        </li>
                    </ul>
                </ItemTemplate>
            </asp:Repeater>