0

我是一名新的 ASP.NET 开发人员,我开发了一个简单的基于 Web 的测验引擎应用程序,类似于 ASP.NET 网站中解释的应用程序。应用程序应该显示不同类型的问题,例如具有单个答案或多个答案的多项选择问题。我现在正在努力解决将显示问题及其可能选择(两个选择或 4 或 5 个选择)的查询。我有以下数据库设计:

Questions Table: QuestionID, Question, QuestionOrder, AnswerExplanation
Answers Table: AnswerID, Answer
Quiz Table: QuizID, Title, Description
QuizContent Table: ID, QuizID, QuestionID, AnswerID, isCorrect

(isCorrect 是一个标志,表示该问题的正确答案)

我首先按照 StackOverFlow 中某人的建议将其实现为嵌套的 GridView。但是现在我不知道如何仅检索带有可能答案的问题,然后单击下一步按钮转到另一个问题。那么你能帮我修改一下吗?

我的 ASP.NET 代码:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
                        DataKeyNames="QuestionID" DataSourceID="SqlDataSource1">
                        <Columns>
                            <asp:BoundField DataField="QuestionID" HeaderText="QuestionID" 
                                InsertVisible="False" ReadOnly="True" SortExpression="QuestionID" />
                            <asp:BoundField DataField="Question" HeaderText="Question" 
                                SortExpression="Question" />
                            <asp:BoundField DataField="QuestionOrder" HeaderText="QuestionOrder" 
                                SortExpression="QuestionOrder" />
                            <asp:BoundField DataField="AnswerExplanation" HeaderText="AnswerExplanation" 
                                SortExpression="AnswerExplanation" />
                            <asp:TemplateField>
                                <ItemTemplate>
                                    <asp:GridView ID="AnswersGridView" runat="server" AutoGenerateColumns="false"
                                                    DataKeyNames="AnswerID" DataSourceID="SqlDataSource2">
                                        <Columns>
                                            <asp:BoundField DataField="AnswerID" HeaderText="AnswerID" 
                                                InsertVisible="False" ReadOnly="True" SortExpression="AnswerID" />
                                            <asp:BoundField DataField="Answer" HeaderText="Answer" 
                                                SortExpression="Answer" />
                                        </Columns>
                                    </asp:GridView>
                                    <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
                                                ConnectionString="<%$ ConnectionStrings:Quiz2ConnectionString %>" 
                                                SelectCommand="SELECT * FROM [Answers]"></asp:SqlDataSource>
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>
                    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:Quiz2ConnectionString %>" 
                        SelectCommand="SELECT * FROM [Questions]"></asp:SqlDataSource>

现在,我必须提出一个查询,它可以显示任何类型的问题及其可能的答案或选择(2 个或 4 个或 6 个选择),那么该怎么做呢?

注意:我是否应该在我的设计中使用 QuizID 作为 SessionParameter,如 ASP.NET 代码所示?

4

1 回答 1

0

If I understand you correctly then change PageSize=1 on parent Gridview. This will display only one row of parent GridView. Which is probably the questions Gridview. Also change AllowPaging=true. oh... you seem to be very new. The query you have written is not correct. Study Sql and learn .net parameterized queries. In case you use the Master-Child relationship as you did then the child grid will use the SelectedDatakey.Value to provide to the child query. " SelectCommand="SELECT * FROM [Answers] where QuestionId=@QuesionId">

you also have to include QuestionId in the Answers table for foreign key relationship. YOu seem very new first study. databases and query then you will be alittle at ease.

于 2012-07-28T19:13:17.520 回答