英語は私の母国語ではありません。タイプミスをお許しください。
アンケート系のアプリを作っているのですが、どうアプローチすればいいのかわからないので試行錯誤しています。
私は質問クラスを持っています
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
1つの質問が持つ可能性があります
- 1つのテキストボックス
- ラジオボタンリスト
- チェックボックスリスト
この場合、私の質問クラスは持つべきですかList<WebControl>
、それともただ持つべきWebControl
ですか?
また、リピーター内で Web コントロールをレンダリングするにはどうすればよいですか?