Search code examples
asp.netdata-bindingrepeater

Repeater's Container.ItemIndex always 0?


I'm trying to set the first RadioButton in a Repeater as checked:

<asp:RadioButton runat="server" GroupName="ApplicationOption"
    Checked="<%# new Func<bool>(() => { 
         System.Diagnostics.Debugger.Break(); 
         return !IsPostBack && Container.ItemIndex == 0; })() %>" />    

The Debugger.Break call causes the execution to break in Debug mode, so I can inspect the values. Every time it breaks, Container.ItemIndex is 0, whereas I expect it to be 0, 1 or 2.

The repeater's DataSource is a list of 3 items. I do not want to use Code-Behind; i.e. I want to keep everything in the markup.

What am I missing?


Solution

  • Make sure the Repeater is only DataBound once, and make sure the DataSource is what you think it is.

    The problem was that the the Repeater was not DataBound once with a DataSource of three items, but it was DataBound three times with a DataSource of 1 item. :/

    Yes, I'm not sure why a Repeater was even used here either.