在ASP.NET中计算在线考试网站的百分比并显示正确的答案 [英] Calculating percentage and displaying correct answer for online examination website in ASP.NET

查看:91
本文介绍了在ASP.NET中计算在线考试网站的百分比并显示正确的答案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿大家我在asp.net的网上考试网站项目我想计算百分比,显示正确答案的数字,最后得分(乘以[标记]和没有正确的答案)这里是我的代码它只显示正确的答案而不是错误的答案





谢谢!



我的尝试:



  protected   void  examsubmit_Click( object  sender,EventArgs e){

DataTable dt = new DataTable();
string sqlStatement = SELECT * FROM [生物学];



SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings [ RegistrationConnectionString2]。ConnectionString);

使用(SqlCommand cmd = new SqlCommand(sqlStatement,con))
{
cmd.CommandType = CommandType.Text;
使用(SqlDataAdapter da = new SqlDataAdapter(cmd))
{
da.Fill(dt);

if (dt.Rows.Count > 0
{
int index = 0 ;
foreach (GridViewRow row in grdquestions.Rows)
{
RadioButton rb1 =(RadioButton)row.FindControl( Option1);
RadioButton rb2 =(RadioButton)row.FindControl( Option2);
RadioButton rb3 =(RadioButton)row.FindControl( Option3);
RadioButton rb4 =(RadioButton)row.FindControl( Option4);
//
int marks = Convert.ToInt32(dt.Rows [index] [ Marks]);
if (rb1!= null || rb2!= null || rb3!= null || rb4!= null

if (rb1.Text == dt.Rows [index] [ 回答]。ToString())
{
// 如果匹配则执行某些操作

rb1.Checked = true ;


}

else if (rb2.Text == dt.Rows [index] [ 答案]。ToString() )
{
// 如果匹配则执行某些操作

rb2.Checked = true ;


}

else if (rb3.Text == dt.Rows [index] [ 答案]。ToString() )
{
// 如果匹配则执行某些操作

rb3.Checked = true ;


}

else if (rb4.Text == dt.Rows [index] [ 答案]。ToString() )
{
// 如果匹配则执行某些操作

rb4.Checked = true ;


}
index ++;


int total = index * marks;
Label2.Text = FinalScore为: + total;


}


}

}

}


}

解决方案

那是因为你只告诉它显示总数:即索引*标记
你在循环中设置它,所以它只会显示最后一行的数据。



如果你想显示其他信息,你必须添加代码来做到这一点! (并且可能在循环之外进行检查所有答案......)


hey everyone i am on online examination website project in asp.net i want to calculate the percentage , to display the no of correct answers , and the final score by(multiplying [marks] and no of correct answers) here is my code it only displays correct answers not the incorrect answers


THANK YOU!

What I have tried:

protected void examsubmit_Click(object sender, EventArgs e) {

    DataTable dt = new DataTable();
    string sqlStatement = "SELECT * FROM [Biology]";



      SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString2"].ConnectionString);

        using (SqlCommand cmd = new SqlCommand(sqlStatement, con))
        {
            cmd.CommandType = CommandType.Text;
            using (SqlDataAdapter da = new SqlDataAdapter(cmd))
            {
                da.Fill(dt);

                if (dt.Rows.Count > 0)
                {
                    int index = 0;
                    foreach (GridViewRow row in grdquestions.Rows)
                    {
                        RadioButton rb1 = (RadioButton)row.FindControl("Option1");
                        RadioButton rb2 = (RadioButton)row.FindControl("Option2");
                        RadioButton rb3 = (RadioButton)row.FindControl("Option3");
                        RadioButton rb4 = (RadioButton)row.FindControl("Option4");
                        //
                        int marks = Convert.ToInt32(dt.Rows[index]["Marks"]);
                        if (rb1 != null || rb2 != null || rb3 != null || rb4 != null)

                            if (rb1.Text == dt.Rows[index]["Answer"].ToString())
                            {
                                //do something if matched

                                rb1.Checked = true;


                            }

                            else if (rb2.Text == dt.Rows[index]["Answer"].ToString())
                            {
                                //do something if matched

                                rb2.Checked = true;


                            }

                            else if (rb3.Text == dt.Rows[index]["Answer"].ToString())
                            {
                                //do something if matched

                                rb3.Checked = true;


                            }

                            else if (rb4.Text == dt.Rows[index]["Answer"].ToString())
                            {
                                //do something if matched

                                rb4.Checked = true;


                            }
                                index++;


                        int total =index * marks;
                        Label2.Text = "FinalScore is :" + total;


                          }


                        }

                    }

                }


            }

解决方案

That's because you have only told it to display the total: i.e. index * marks
And you are setting that inside a loop, so it will only ever show the last rows worth of data.

If you want to to show other information, you have to add code to do that! (And probably do it outside the loop which checks all of the answers...)


这篇关于在ASP.NET中计算在线考试网站的百分比并显示正确的答案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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