EDIT:
There are few issues with your approaches:
You are creating
List<MyControlType>
and trying to use it as datasource.You are initializing and adding myItem to the List and hoping that after Databinding you can find the UserControl in Repeater.
You are adding the UserControl to the Repeater in markup and after DataBinding you are finding the repeater in repeater's item and hoping that it will have the value you have assigned to myItem.
Solution:
Use a better DataSource to test, e.g. List<string>
. Here's how the repeater might look(in repescet to test data):
<asp:Repeater ID="repeater" runat="server">
<ItemTemplate>
<pre:MyControlType IsRetained='<%#Container.DataItem == "item 1" ? true : false %>' runat="server" />
</ItemTemplate>
</asp:Repeater>
And in my code I am testing like this:
protected void someButton_Click(object sender, EventArgs e)
{
var lst = new List<string>() { "item 1", "item 2", "item 3" };
repeater.DataSource = lst;
repeater.DataBind();
// test code
MyControlType realItem1 = repeater.Items[0].Controls[1] as MyControlType;
MyControlType realItem2 = repeater.Items[1].Controls[1] as MyControlType;
MyControlType realItem3 = repeater.Items[2].Controls[1] as MyControlType;
bool test1 = realItem1.IsRetained; // true (data == "item 1")
bool test2 = realItem2.IsRetained; // false (data != "item 1")
bool test3 = realItem3.IsRetained; // false (data != "item 1")
}
You can see we have expected results here.