如何通过一个问题在测验中显示“完成"按钮? [英] How to show the FINISHED button in the quiz with one question?

查看:69
本文介绍了如何通过一个问题在测验中显示“完成"按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在正在开发的Web应用程序有一个称为测验引擎的东西,它为用户提供由一个或多个问题组成的简短测验.现在,我的测验页面有问题.测验可能包含一个或多个问题.我遇到的主要问题是:如果测验由一个问题组成,当用户参加此测验时,他将看到下一个"按钮,而不是完成"按钮.但是,如果测验包含多个问题,则他将在页面中看到包含最后一个问题的完成"按钮.我不知道为什么会这样.有什么帮助吗?


为了创建测验引擎,我使用了 ASP.NET网站中的Toturial 进行创建.

我的ASP.NET代码:

<asp:DetailsView ID="questionDetails" runat="server" Height="50px" Width="550px" AutoGenerateRows="False" CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None">
                    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
                    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" CssClass="generaltext" />
                    <FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" CssClass="boldtext" Width="80px" />
                    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                    <Fields>
                        <asp:BoundField DataField="Question" HeaderText="Question:" SortExpression="Question" />
                        <asp:BoundField DataField="Answer1" HeaderText="A:" SortExpression="Answer1" />
                        <asp:BoundField DataField="Answer2" HeaderText="B:" SortExpression="Answer2" />
                        <asp:BoundField DataField="Answer3" HeaderText="C:" SortExpression="Answer3" />
                        <asp:BoundField DataField="Answer4" HeaderText="D:" SortExpression="Answer4" />
                    </Fields>
                    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <EditRowStyle BackColor="#999999" />
                    <AlternatingRowStyle BackColor="White" ForeColor="#284775" CssClass="generaltext" />
                </asp:DetailsView>
                 
                <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:testConnectionString %>" SelectCommand="SELECT [QuestionID], [Question], [Answer1], [Answer2], [Answer3], [Answer4], [CorrectAnswer], [QuestionOrder] FROM [Question] WHERE ([QuizID] = @QuizID) ORDER BY [QuestionOrder]">
                    <SelectParameters>
                        <asp:SessionParameter SessionField="QuizID" Type="Int32" Name="QuizID" DefaultValue="0" />
                    </SelectParameters>
                </asp:SqlDataSource>







我的后台代码:

 受保护的 无效 Page_Load(对象发​​件人,EventArgs e)
{
    questionDetails.DataBind();
}

受保护的 无效 nextButton_Click(对象发​​件人,EventArgs e)
{
    // 保存以前的答案
    System.Data.DataRowView dr =(System.Data.DataRowView)questionDetails.DataItem;

    // 创建Answer对象以保存值
    回答一个=  Answer();
    a.QuestionID = dr [" ].ToString();
    a.CorrectAnswer = dr [" ].ToString();
    a.UserAnswer = answerDropDownList.SelectedValue.ToString();

    ArrayList al =(ArrayList)Session [" ];
    al.Add(a);

    Session.Add(" 等);

    如果(questionDetails.PageIndex == questionDetails.PageCount- 1 )
    {
        // 评估答案
        Response.Redirect(" );
    }
    其他
    {
        questionDetails.PageIndex ++;
    }

    如果(questionDetails.PageIndex == questionDetails.PageCount- 1 )
    {
        nextButton.Text = " ;
    }

}




**如何解决此问题?**

解决方案

ConnectionStrings:testConnectionString%>"SelectCommand =" SELECT [QuestionID],[Question],[Answer1] ,[Answer2],[Answer3],[Answer4],[CorrectAnswer],[QuestionOrder]来自[Question]的位置([QuizID] = @QuizID),按[QuestionOrder]排序. < SelectParameters> < asp:SessionParameter SessionField ="QuizID" Type ="Int32" Name ="QuizID" DefaultValue ="0"/> </SelectParameters> </asp:SqlDataSource>







我的后台代码:

 受保护的 无效 Page_Load(对象发​​件人,EventArgs e)
{
    questionDetails.DataBind();
}

受保护的 无效 nextButton_Click(对象发​​件人,EventArgs e)
{
    // 保存以前的答案
    System.Data.DataRowView dr =(System.Data.DataRowView)questionDetails.DataItem;

    // 创建Answer对象以保存值
    回答一个=  Answer();
    a.QuestionID = dr [" ].ToString();
    a.CorrectAnswer = dr [" ].ToString();
    a.UserAnswer = answerDropDownList.SelectedValue.ToString();

    ArrayList al =(ArrayList)Session [" ];
    al.Add(a);

    Session.Add(" 等);

    如果(questionDetails.PageIndex == questionDetails.PageCount- 1 )
    {
        // 评估答案
        Response.Redirect(" );
    }
    其他
    {
        questionDetails.PageIndex ++;
    }

    如果(questionDetails.PageIndex == questionDetails.PageCount- 1 )
    {
        nextButton.Text = " ;
    }

}




**如何解决此问题?**问题将按钮文本更改为完成",否则将文本更改为下一步".
同样,检查下一步"按钮单击事件是否还有其他问题,如果没有,则将其更改为完成".


The web application that I am developing right now has something called quiz engine which provides users with short quizzes which consist of one question or more. Now, I have a problem with the QUIZ page. The quiz may consist of one question or more. The main problem that I have is following: If the quiz consists of one question, when the user comes to this quiz, he will see the NEXT button instead of seeing the FINISHED button. However, if the quiz consists of more than one question, he will see the FINISHED button in the page with the last question. I don''t know why this is happening with me. Any help please?


For creating the Quiz engine, I used the Toturial in the ASP.NET website for creating it.

My ASP.NET code:

<asp:DetailsView ID="questionDetails" runat="server" Height="50px" Width="550px" AutoGenerateRows="False" CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None">
                    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
                    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" CssClass="generaltext" />
                    <FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" CssClass="boldtext" Width="80px" />
                    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                    <Fields>
                        <asp:BoundField DataField="Question" HeaderText="Question:" SortExpression="Question" />
                        <asp:BoundField DataField="Answer1" HeaderText="A:" SortExpression="Answer1" />
                        <asp:BoundField DataField="Answer2" HeaderText="B:" SortExpression="Answer2" />
                        <asp:BoundField DataField="Answer3" HeaderText="C:" SortExpression="Answer3" />
                        <asp:BoundField DataField="Answer4" HeaderText="D:" SortExpression="Answer4" />
                    </Fields>
                    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <EditRowStyle BackColor="#999999" />
                    <AlternatingRowStyle BackColor="White" ForeColor="#284775" CssClass="generaltext" />
                </asp:DetailsView>
                 
                <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:testConnectionString %>" SelectCommand="SELECT [QuestionID], [Question], [Answer1], [Answer2], [Answer3], [Answer4], [CorrectAnswer], [QuestionOrder] FROM [Question] WHERE ([QuizID] = @QuizID) ORDER BY [QuestionOrder]">
                    <SelectParameters>
                        <asp:SessionParameter SessionField="QuizID" Type="Int32" Name="QuizID" DefaultValue="0" />
                    </SelectParameters>
                </asp:SqlDataSource>







My code-behind:

protected void Page_Load(object sender, EventArgs e)
{
    questionDetails.DataBind();
}

protected void nextButton_Click(object sender, EventArgs e)
{
    // Save off previous answers
    System.Data.DataRowView dr = (System.Data.DataRowView)questionDetails.DataItem;

    // Create Answer object to save values
    Answer a = new Answer();
    a.QuestionID = dr["QuestionOrder"].ToString();
    a.CorrectAnswer = dr["CorrectAnswer"].ToString();
    a.UserAnswer = answerDropDownList.SelectedValue.ToString();

    ArrayList al = (ArrayList)Session["AnswerList"];
    al.Add(a);

    Session.Add("AnswerList", al);

    if (questionDetails.PageIndex == questionDetails.PageCount - 1)
    {
        // Go to evaluate answers
        Response.Redirect("Results.aspx");
    }
    else
    {
        questionDetails.PageIndex++;
    }

    if (questionDetails.PageIndex == questionDetails.PageCount - 1)
    {
        nextButton.Text = "Finished";
    }

}




**SO HOW TO FIX THIS PROBLEM?**

解决方案

ConnectionStrings:testConnectionString %>" SelectCommand="SELECT [QuestionID], [Question], [Answer1], [Answer2], [Answer3], [Answer4], [CorrectAnswer], [QuestionOrder] FROM [Question] WHERE ([QuizID] = @QuizID) ORDER BY [QuestionOrder]"> <SelectParameters> <asp:SessionParameter SessionField="QuizID" Type="Int32" Name="QuizID" DefaultValue="0" /> </SelectParameters> </asp:SqlDataSource>







My code-behind:

protected void Page_Load(object sender, EventArgs e)
{
    questionDetails.DataBind();
}

protected void nextButton_Click(object sender, EventArgs e)
{
    // Save off previous answers
    System.Data.DataRowView dr = (System.Data.DataRowView)questionDetails.DataItem;

    // Create Answer object to save values
    Answer a = new Answer();
    a.QuestionID = dr["QuestionOrder"].ToString();
    a.CorrectAnswer = dr["CorrectAnswer"].ToString();
    a.UserAnswer = answerDropDownList.SelectedValue.ToString();

    ArrayList al = (ArrayList)Session["AnswerList"];
    al.Add(a);

    Session.Add("AnswerList", al);

    if (questionDetails.PageIndex == questionDetails.PageCount - 1)
    {
        // Go to evaluate answers
        Response.Redirect("Results.aspx");
    }
    else
    {
        questionDetails.PageIndex++;
    }

    if (questionDetails.PageIndex == questionDetails.PageCount - 1)
    {
        nextButton.Text = "Finished";
    }

}




**SO HOW TO FIX THIS PROBLEM?**


Use single button for showing Next and finished and check on PageLoad whether there are more than one questions or only one.If there is only one question change the button text to Finished otherwise change text to Next.
Similarly check on Next button click event whether there are more questions or not,if not then change it to Finished.


这篇关于如何通过一个问题在测验中显示“完成"按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆