英语不是我的母语;请原谅打字错误。
我正在创建一个调查类型的应用程序,但我不确定我应该如何处理,所以我一直在做一些试验和错误。
我有一个问题课
public class Question
{
    public int QuestionID;
    public string QuestionText;
    public int InputTypeID;
    public List<WebControl> Controls;
    public Question()
    {
        //initialize fields;
    }
    internal Question(int id, string text, int inputTypeId)
    {
        //assign parameters to fields
        switch(inputTypeId)
        {
            case 1:
                //checkbox
                break;
            case 2:
                //textbox
                TextBox t = new TextBox();
                Controls = new List<WebControl>();
                Controls.Add(t);
                break;
            ...
        }
    }
}
我的 Question.aspx 看起来像这样:
<asp:Repeater ID="repeater" runat="server">
    <ItemTemplate>
        //Want to display a control dynamically here
    </ItemTemplate>
</asp:Repeater>
我试过这个,但它显然没有工作......
<asp:Repeater ID="repeater" runat="server">
    <ItemTemplate>
        <%# DataBinder.Eval(Container.DataItem, "Controls") %>
    </ItemTemplate>
</asp:Repeater>
我就明白了。
System.Collections.Generic.List`1[System.Web.UI.WebControls.WebControl] System.Collections.Generic.List`1
一个问题可能有
- 一个文本框
- 单选按钮列表
- 复选框列表
在这种情况下,我的 Question 课程应该有List<WebControl>还是只有WebControl?
另外,我怎样才能在转发器中渲染 webcontrol?