1
grid.DataSource = list; //list is a Question[], each Question contains a QuestionText and Choices[]
grid.DataBind();

我怎样才能向他们展示:http: //i.imgur.com/MUQK0.png
我应该在 asp 代码中编码什么?

<asp:GridView ID="OptionsView" runat="server" AutoGenerateColumns="False" >
<Columns>
<asp:BoundField DataField="//here,what should i code?" HeaderText="Options" />
</Columns>
</asp:GridView>
4

1 回答 1

0

对于这样的自定义输出,您将需要使用TemplateField

<asp:TemplateField>
    <ItemTemplate>
        <%-- you can use custom tags here and
             Eval("Property") to get values from the
             data source, or ((Question)Container.DataItem).Property
    </ItemTemplate>
</asp:TemplateField>

对于您的第二列,您将需要第二个显示控件,该控件可以显示多个数据输出,例如 aListViewRepeater。例如,您如何在第二列中显示一个无序列的选项列表(这将在 another 中asp:TemplateField):

<ul>
<asp:Repeater DataSource='<%#((Question)Container.DataItem).Choices#>' ...
    <ItemTemplate>
        <li><%#Eval("ChoiceText")#></li>
    </ItemTemplate>
</asp:Repeater>
</ul>
于 2012-04-20T01:41:15.577 回答