寻找合适的DataBound控件来实现问题页面

时间:2011-08-24 10:14:09

标签: c# asp.net databound-controls

我期待在我的应用程序中找到合适的asp.net DataBound控件(C#)。

我想创建一个考试页面,其中每个页面显示10个问题,每个问题都有一个Label控件和一个radiobutton控件来显示选项,要绑定到DataBound控件的数据可能有多行,其中每行代表每个问题。

我发现DetailView控件非常适合我的要求,但我无法设置页面大小。

请帮忙提出一些建议和建议,谢谢你提前。

2 个答案:

答案 0 :(得分:1)

我建议您使用Repeater控件,因为您可以非常轻松地自定义它的设计以满足您的需求。

以下是有关如何使用它的两个教程:

http://www.w3schools.com/aspnet/aspnet_repeater.asp

http://www.learn-asp.net/asptutorials/Repeater.aspx

<强>更新

Repeater没有包含分页,所以你必须添加它:

http://blog.divergencehosting.com/2009/03/25/adding-paging-repeater/

其他选项是使用包含分页的GridView。

答案 1 :(得分:1)

我会使用DataList或ListView,因为它允许您为每个项目输入模板。我在转发器上选择这些的原因是因为你可以使用数据键,这可能会派上用场。

以下是一个如何实现问题列表的简单示例:

<asp:DataList ID="DataList1" runat="server" DataKeyField="QuestionID" ...>
    <ItemTemplate>
        <asp:Label ID="Label1" runat="server" Text='<%#Eval("Question")%>' />
        <asp:RadioButton ID="RadioButton1" runat="server" Text="Yes" GroupName="QuestionAnswer" ... />
        <asp:RadioButton ID="RadioButton2" runat="server" Text="No" GroupName="QuestionAnswer" ... />
    </ItemTemplate>
</asp:DataList>