循环在动态多视图中返回值2时返回值1 [英] Loop returns a value of 1 when it should return a value of two in a dynamic multiview

查看:98
本文介绍了循环在动态多视图中返回值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!

推荐答案

我们没有数据可以解决这个问题。您将不得不在事件处理程序代码的第一行代码上放置一个断点,并逐步调试代码,在调试器中逐行检查并检查每行上的变量值,看它们是否符合您的预期。
We don't have the data to be able to troubleshoot this one. You are going to have to put a breakpoint on the first line of code in the event handler code and step through the code, lineby-line in the debugger and examine the values of the variables on each line to see if they are what you expect.


您应该学习尽快使用调试器。而不是猜测你的代码在做什么,现在是时候看到你的代码执行并确保它完成你期望的。



调试器允许你跟踪执行逐行检查变量,你会看到有一点它会停止你所期望的。

在Visual Studio 2010中掌握调试 - 初学者指南 [ ^ ]

http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html [ ^ ]

https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html [ ^ ]
You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.

The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing what you expect.
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html[^]
https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html[^]


我想我会我不得不花时间使用断点。感谢您的见解。
I guess I'll have to take my time using breakpoints. Thanks for the insight.


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

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