本文介绍了循环在动态多视图中返回值2时返回值1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我执行了一个循环并选择了所有正确的选项,期望获得Final_Score值2和Perc值100但是我总是得到Final_Score为1且Perc值为0.



这是代码:



I performed a loop and selected all the right options with the expectation of getting a Final_Score value of 2 and a Perc value of 100 but instead i always get a Final_Score of 1 and a Perc value of 0.

This is the code:

int number = 2;

btnSave.Click += new EventHandler(delegate(object sender, EventArgs ee)
            {

                int Final_Score = 0;
                View vw = new View();
                for (int i = 0; i < number; i++)
                {
                    vw.ID = "vw" + i.ToString();

                    RadioButton radio1 = (RadioButton)form1.FindControl("radio" + vw.ID + "1");
                    RadioButton radio2 = (RadioButton)form1.FindControl("radio" + vw.ID + "2");
                    RadioButton radio3 = (RadioButton)form1.FindControl("radio" + vw.ID + "3");
                    RadioButton radio4 = (RadioButton)form1.FindControl("radio" + vw.ID + "4");
                    RadioButton radio5 = (RadioButton)form1.FindControl("radio" + vw.ID + "5");
                    Label lab1 = (Label)form1.FindControl("Label" + vw.ID + "1");
                    Label lab2 = (Label)form1.FindControl("Label" + vw.ID + "2");
                    Label lab3 = (Label)form1.FindControl("Label" + vw.ID + "3");
                    Label lab4 = (Label)form1.FindControl("Label" + vw.ID + "4");
                    Label lab5 = (Label)form1.FindControl("Label" + vw.ID + "5");
                    HiddenField hides = (HiddenField)form1.FindControl("hidden" + vw.ID + "1");

                    string label1 = lab1.Text;
                    string label2 = lab1.Text;
                    string label3 = lab1.Text;
                    string label4 = lab1.Text;;
                    string label5 = lab1.Text;;
                    string ans = hides.Value;

                    if (radio1.Checked == true)
                    {
                        if (ans == label1)
                        {
                            Final_Score = Final_Score + 1;
                        }
                    }
                    else if (radio2.Checked == true)
                    {
                        if (ans == label2)
                        {
                            Final_Score = Final_Score + 1;
                        }
                    }
                    else if (radio3.Checked == true)
                    {
                        if (ans == label3)
                        {
                            Final_Score = Final_Score + 1;
                        }
                    }
                    else if (radio4.Checked == true)
                    {
                        if (ans == label4)
                        {
                            Final_Score = Final_Score + 1;
                        }
                    }
                    else if (radio5.Checked == true)
                    {
                        if (ans == label5)
                        {
                            Final_Score = Final_Score + 1;
                        }
                    }
                }
                int count = number;
                int Perc = (Final_Score / count) * 100;
                int UserID = Convert.ToInt32(Session["UserID"].ToString());
                int GroupID = Convert.ToInt32(Session["GroupID"].ToString());

                try
                {
                    InsertScore(UserID, examid, GroupID, Final_Score, Perc, count, Final_Score);
                }
                catch
                {
                    throw;
                }

                Response.Redirect("./testresult.aspx");
            });





我尝试过:



我已尽可能地排除故障,但我似乎无法发现我一定做错了什么。需要帮助!



What I have tried:

I've troubleshooted as much as i think i can but cant seem to spot what i must be doing wrong. Need help!

推荐答案




这篇关于循环在动态多视图中返回值2时返回值1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-04 20:23