本文介绍了在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 answersTHANK 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; } } } } } 解决方案 这篇关于在ASP.NET中计算在线考试网站的百分比并显示正确的答案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-30 03:15