Unable to populate RadioButtonList inside ASP.NET Repeater Template
<p>I am trying to populate a repeater containing a label and a RadioButtonList in an ASP.NET webform to make a small quiz.</p>

<p>These are the classes I am using:</p>

<pre><code>public class Option
{
    private string _body;
    private bool? _isCorrect;

    #region properties
    public string Body
    {
        get { return _body; }
    }

    public bool? IsCorrect
    {
        get { return _isCorrect; }
    }

    #endregion

    #region constructors

    public Option(string body)
    {
        _body = body;
        _isCorrect = null;
    }

    public Option(string body, bool isCorrect)
    {
        _body = body;
        _isCorrect = isCorrect;
    }
    #endregion

    #region methods

    public override string ToString()
    {
        return _body;
    }

    #endregion

}
</code></pre>

<p>and: </p>

<pre><code>public class Question
{
    private string _body;
    private Option[] _optionsArray;
    private List&lt;Option&gt; _optionsList;

    #region properties

    public string Body
    {
        get { return _body; }
    }

    public Option[] Options
    {
        get { return _optionsArray; }
    }

    public List&lt;Option&gt; OptionsList
    {
        get { return _optionsList; }

    }
    #endregion


    #region constructors

    public Question(string body, Option[] options)
    {
        _body = body;

        _optionsArray = options;

        _optionsList = new List&lt;Option&gt;();
        foreach (Option opt in options)
        {
            _optionsList.Add(opt);
        }
    }

    #endregion

    #region methods

    public override string ToString()
    {
        return _body;
    }

    public List&lt;Option&gt; GetOptions()
    {
        return OptionsList;
    }

    #endregion

}
</code></pre>

<p>My webform looks like this:</p>

<pre><code>&lt;div runat="server" ID="quizDiv"&gt;



    &lt;br /&gt;
    &lt;br /&gt;

    &lt;asp:Repeater ID="Repeater1" runat="server"&gt;
        &lt;ItemTemplate&gt;
            &lt;%--&lt;asp:Label ID="questionBody" runat="server" Text=&lt;%# DataBinder.Eval(Container.DataItem, "Body") %&gt;&gt;--%&gt;
            &lt;asp:Label ID="questionBody" runat="server" Text=&lt;%# ((Question)Container.DataItem).Body %&gt;&gt;
            &lt;asp:radiobuttonlist ID="blah" runat="server" DataTextField="Body" DataValueField="Body" DataSource=&lt;%# ((Question)Container.DataItem).OptionsList %&gt; &gt;

            &lt;/asp:radiobuttonlist&gt;  
            &lt;/asp:Label&gt;
        &lt;/ItemTemplate&gt;
    &lt;/asp:Repeater&gt;
    &lt;br /&gt;


&lt;/div&gt;
</code></pre>

<p>and the code-behind like so:</p>

<pre><code>protected void btnStart_Click(object sender, EventArgs e)
    {
        Dataset1 ds = new Dataset1();
        question = ds.CreateQuestion();

        List&lt;Question&gt; qts = new List&lt;Question&gt;();
        qts.Add(question);

        Repeater1.DataSource = qts;
        Repeater1.DataBind();

    }
</code></pre>

<p>For the time being I am just using one question. The label displaying my question shows up fine, but no radio buttons show up for displaying the answer options. I have gone through many samples, and this seems to work for people when they use data from a DB via a DataTable or DataSet. However no matter how much I to play around with the Datasource, DataValueField and DataTextField parameters the RadioButtonList remains utterly barren. As you can see, I initially used an array of Option and also tried a List but to no avail.</p>

<p>What am I missing here?</p>

<p><hr>
<strong>EDIT - Found my mistake</strong>
I had the <code>&lt;asp:label&gt;</code> and <code>&lt;asp:radiobuttonlist&gt;</code> tags nested wrong! The label was encapsulating the radiobuttonlist and causing the problem from what I can make out.</p>

<p><hr>
<strong>ALTERNATIVE - thanks to balexandre</strong></p>

<p>balexandre did provide a workable alternative by using only code-behing. Thank you!</p>

<p>I am including the code listing of this alternative for anyone who needs it and happens across this post.</p>

<p>Change the markup to look like this:</p>

<pre><code>&lt;asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound"&gt;
        &lt;ItemTemplate&gt;
            &lt;%--&lt;asp:Label ID="questionBody" runat="server" Text=&lt;%# DataBinder.Eval(Container.DataItem, "Body") %&gt;&gt;--%&gt;
            &lt;asp:Label ID="questionBody" runat="server" Text=&lt;%# ((Question)Container.DataItem).Body %&gt;&gt;
            &lt;/asp:Label&gt;
            &lt;asp:radiobuttonlist ID="blah" runat="server" &gt;

            &lt;/asp:radiobuttonlist&gt;  

        &lt;/ItemTemplate&gt;
    &lt;/asp:Repeater&gt;
</code></pre>

<p>and the code-behind must have the event handler:</p>

<pre><code>protected void Repeater1_ItemDataBound(Object Sender, RepeaterItemEventArgs e)
    {

        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {

            RadioButtonList rbl = (RadioButtonList)e.Item.FindControl("blah");
            // do anything with your rbl
            foreach (Option opt in question.Options)
            {
                rbl.Items.Add(opt.ToString());
            }
        }
    }  
</code></pre>
