Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 现在我该怎么做呢?:)您将需要5个问题(文本),如表中所示。我们有一个栏目可以找到正确答案。您只需再增加一列,即可获得正确答案的分数。如果你因为错误的答案而获得分数,那么你需要为每5个可能的问题的每一个分数增加5栏。如果只有一个正确答案,则只需要额外的一列_C#_Asp.net_Web Applications - Fatal编程技术网

C# 现在我该怎么做呢?:)您将需要5个问题(文本),如表中所示。我们有一个栏目可以找到正确答案。您只需再增加一列,即可获得正确答案的分数。如果你因为错误的答案而获得分数,那么你需要为每5个可能的问题的每一个分数增加5栏。如果只有一个正确答案,则只需要额外的一列

C# 现在我该怎么做呢?:)您将需要5个问题(文本),如表中所示。我们有一个栏目可以找到正确答案。您只需再增加一列,即可获得正确答案的分数。如果你因为错误的答案而获得分数,那么你需要为每5个可能的问题的每一个分数增加5栏。如果只有一个正确答案,则只需要额外的一列,c#,asp.net,web-applications,C#,Asp.net,Web Applications,现在我该怎么做呢?:)您将需要5个问题(文本),如表中所示。我们有一个栏目可以找到正确答案。您只需再增加一列,即可获得正确答案的分数。如果你因为错误的答案而获得分数,那么你需要为每5个可能的问题的每一个分数增加5栏。如果只有一个正确答案,则只需要额外的一列来保存正确答案的分数。上面的代码显示了我们如何合计正确答案和错误答案。这段代码很容易修改,可以在“问题点”列中为正确答案加上分数。给出一个你没有错误或正确答案的答案?然后你需要5个额外的列,点1,点2,点3..点5。因此,您需要在数据库中包含每


现在我该怎么做呢?:)您将需要5个问题(文本),如表中所示。我们有一个栏目可以找到正确答案。您只需再增加一列,即可获得正确答案的分数。如果你因为错误的答案而获得分数,那么你需要为每5个可能的问题的每一个分数增加5栏。如果只有一个正确答案,则只需要额外的一列来保存正确答案的分数。上面的代码显示了我们如何合计正确答案和错误答案。这段代码很容易修改,可以在“问题点”列中为正确答案加上分数。给出一个你没有错误或正确答案的答案?然后你需要5个额外的列,点1,点2,点3..点5。因此,您需要在数据库中包含每个qeustion所需的点数。(除非ans1的分数都是1分,ans2的分数都是2分,等等。但是如果每个问题的分数都是某个数字,那么只需添加5个额外的栏来保留每个答案的分数。然后你可以使用贴出的近乎精确的代码来汇总给出的答案-而不是像代码那样添加+1,只需添加点1-5 c即可给定答案的列值。
  <asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
    <table>
        <tr>
            <td> <%#Eval("IDq") %> )  <%#Eval("qustion") %></td></tr>
        <tr>
            <td>
                <asp:RadioButton ID="RadioButton1" runat="server" Text='<%#Eval("ans1")%>' GroupName="quiz" Value="1"></asp:RadioButton>
                <asp:RadioButton ID="RadioButton2" runat="server" Text='<%#Eval("ans2") %>' GroupName="quiz" Value="2"></asp:RadioButton>
                <asp:RadioButton ID="RadioButton3" runat="server" Text='<%#Eval("an3") %>' GroupName="quiz" Value="3"></asp:RadioButton>
                <asp:RadioButton ID="RadioButton4" runat="server" Text='<%#Eval("ans4") %>' GroupName="quiz" Value="4"></asp:RadioButton>
                <asp:RadioButton ID="RadioButton5" runat="server" Text='<%#Eval("ans5") %>' GroupName="quiz" Value="5"></asp:RadioButton>
                <br />
            </td>
        </tr> </table>
</ItemTemplate></asp:Repeater>
the index of the selection (0 to N)
the text value of the selection
the value value of the selection.
 show the score and results after we submit
 tell the user they did NOT answer a question - they MUST!!!
 heck, toss is a cool check box, or X box to show wrong or right.
 Allow a question to only have say 2 answers - not always all 5
    <div style="width:35%">
        <asp:Repeater ID="Repeater1" runat="server">
        <ItemTemplate>
            <div style="float:left">
            <asp:Label ID="Question" runat="server" 
                Text = '<%# Eval("IDq").ToString + " ) " + Eval("question") %>' 
                Font-Size="X-Large">
            </asp:Label>
            </div>
            <div style="float:right">
                <img id="MyImage" runat="server" src="" height="48" width="48" />
            </div>
            <div style="clear:both">

            <asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection="Horizontal" ></asp:RadioButtonList>
            </div>
            <br />
            <hr></hr>
        </ItemTemplate>
      </asp:Repeater>

        <asp:Button ID="cmdDone" runat="server" Text="Submit" />

        <div id="MyError" style="display:none;normal;color:red" runat="server">
            <h2>You have not answered all questions</h2>
            <h2>Please answer all questions before submitting</h2>
        </div>

        <div id="Results" runat="server" style="clear:both; display:none" >
            <h2>Results</h2>
            <asp:TextBox ID="MyCorrect" runat="server"></asp:TextBox>
            <br />
            <asp:TextBox ID="InCorrect" runat="server"></asp:TextBox>
        </div>

    </div>
private DataTable MyTable = new DataTable();

protected void Page_Load(object sender, System.EventArgs e)
{
    if (IsPostBack == false)
    {
        LoadData();
        ViewState["MyTable"] = MyTable;
    }
    else
        MyTable = ViewState["MyTable"];
}

public void LoadData()
{
    using (SqlCommand cmdSQL = new SqlCommand("SELECT * from tblQuestions ORDER BY IDq",
                             new SqlConnection(My.Settings.TEST4)))
    {
        cmdSQL.Connection.Open();
        MyTable.Load(cmdSQL.ExecuteReader);
        Repeater1.DataSource = MyTable;
        Repeater1.DataBind();
    }
}

protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item | e.Item.ItemType == ListItemType.AlternatingItem)
    {
        DataRow MyRow = MyTable.Rows(e.Item.ItemIndex);

        RadioButtonList rBtnList = e.Item.FindControl("RadioButtonList1");
        for (var i = 1; i <= 5; i++)
        {
            var strR = "ans" + i;
            if (IsDBNull(MyRow(strR)) == false)
            {
                ListItem nItem = new ListItem(MyRow(strR), i);
                rBtnList.Items.Add(nItem);
            }
        }
    }
}

protected void cmdDone_Click(object sender, EventArgs e)
{

    // check all rows - make sure all have a answer
    // show check box for correct answers
    // total up correct answers (count)
    // total up wrong answers (count)

    MyError.Style("Display") = "none";


    int Correct = 0;
    int Wrong = 0;
    int NotAnser = 0;

    foreach (RepeaterItem ritem in Repeater1.Items)
    {
        RadioButtonList RadioBut = ritem.FindControl("RadioButtonList1");

        if (RadioBut.SelectedIndex >= 0)
        {
            HtmlImage MyImage = ritem.FindControl("MyImage");
            if (MyTable.Rows(ritem.ItemIndex).Item("Answer") == RadioBut.SelectedIndex + 1)
            {
                Correct += 1;
                MyImage.Src = "/Content/ok.png";
            }
            else
            {
                Wrong += 1;
                MyImage.Src = "/Content/reject.png";
            }
        }
        else
        {
            NotAnser += 1;
        }
    }

    // if missed questions then display warning.

    if (NotAnser > 0)
        MyError.Style("Display") = "normal";
    else
    {
        MyCorrect.Text = "Correct answers = " + Correct;
        InCorrect.Text = "Wrong answers = " + Wrong;
        Results.Style("Display") = "normal";
    }
}