473,396 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Grade Does Not Increment!

35
Hi all,
i have a web page which contains a gridview. On this gridview, the user uses a set of radiobuttonlists to select an option. the selected option is then to be compared with the data in a table. I draw out this data using a dataset table adapter. i want to compare the two values and if they are the same, increment Grade by 1. This is my code below. When i run it, grade always remains at zero. Can you please help me check why its not working? thanks
Expand|Select|Wrap|Line Numbers
  1.  string studentAnswer;
  2.     string lecturerAnswer;
  3.     int Grade = 0;
  4.     int i = 1;
  5.  
  6.       public void Button1_Click(object sender, EventArgs e)
  7.     {
  8.         DataSet1TableAdapters.QuestionsTTableAdapter adapter = new DataSet1TableAdapters.QuestionsTTableAdapter();
  9.         DataSet1.QuestionsTDataTable questions = adapter.GetData();
  10.         DataSet1.QuestionsTRow rowT = questions[i];
  11.  
  12.  
  13.         foreach ( GridViewRow row in GridView1.Rows ) 
  14.         {
  15.             lecturerAnswer = rowT.Answers;
  16.             i++;
  17.             RadioButtonList radiolist = (RadioButtonList)row.FindControl("radlist");
  18.  
  19.             if (radiolist != null  )
  20.             {
  21.                 foreach (ListItem litem in radiolist.Items)
  22.                 {
  23.                     if (litem.Selected)
  24.                     {
  25.                         studentAnswer = radiolist.SelectedValue.ToString();
  26.                     }     
  27.                 }
  28.             }
  29.             if (studentAnswer == lecturerAnswer)
  30.             {
  31.                 Grade++;
  32.             }
  33.             else
  34.             {
  35.                 Grade= Grade + 0;
  36.             }
  37.         }
  38.         Label1.Text = "You have Scored " + Grade;
  39.     }
  40.  
Dec 14 '07 #1
1 1235
nateraaaa
663 Expert 512MB
Hi all,
i have a web page which contains a gridview. On this gridview, the user uses a set of radiobuttonlists to select an option. the selected option is then to be compared with the data in a table. I draw out this data using a dataset table adapter. i want to compare the two values and if they are the same, increment Grade by 1. This is my code below. When i run it, grade always remains at zero. Can you please help me check why its not working? thanks
Expand|Select|Wrap|Line Numbers
  1.  string studentAnswer;
  2.     string lecturerAnswer;
  3.     int Grade = 0;
  4.     int i = 1;
  5.  
  6.       public void Button1_Click(object sender, EventArgs e)
  7.     {
  8.         DataSet1TableAdapters.QuestionsTTableAdapter adapter = new DataSet1TableAdapters.QuestionsTTableAdapter();
  9.         DataSet1.QuestionsTDataTable questions = adapter.GetData();
  10.         DataSet1.QuestionsTRow rowT = questions[i];
  11.  
  12.  
  13.         foreach ( GridViewRow row in GridView1.Rows ) 
  14.         {
  15.             lecturerAnswer = rowT.Answers;
  16.             i++;
  17.             RadioButtonList radiolist = (RadioButtonList)row.FindControl("radlist");
  18.  
  19.             if (radiolist != null  )
  20.             {
  21.                 foreach (ListItem litem in radiolist.Items)
  22.                 {
  23.                     if (litem.Selected)
  24.                     {
  25.                         studentAnswer = radiolist.SelectedValue.ToString();
  26.                     }                   
  27.                  }
  28.                  if (studentAnswer == lecturerAnswer)
  29.                     {
  30.                         Grade++;
  31.                      }
  32.                      else
  33.                      {
  34.                          Grade= Grade + 0;
  35.                       } 
  36.             }
  37.                   }
  38.         Label1.Text = "You have Scored " + Grade;
  39.     }
  40.  
See bolded code above. I think the reason that Grade was not being incremented is because the only studentAnswer being compared was the very last studentAnswer in radiolist.Items.

Place this code
Expand|Select|Wrap|Line Numbers
  1. if (studentAnswer == lecturerAnswer)
  2.                     {
  3.                         Grade++;
  4.                      }
  5.                      else
  6.                      {
  7.                          Grade= Grade + 0;
  8.                       } 
after this conditional statement.
Expand|Select|Wrap|Line Numbers
  1.  if (litem.Selected)
  2.                     {
  3.                         studentAnswer = radiolist.SelectedValue.ToString();
  4.                     }     
Nathan
Dec 14 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

35
by: Henry | last post by:
I was doing this program for an exercise in a book. The point was to create a program that would take a numerical grade from a user and convert it to a letter grade (yeah really easy). I tried to...
1
by: sparkid | last post by:
I need immediate help in writing a function program. I have to write a program in functions and use array to store them. I am not familiar with functions and i tried to create it but i fails to...
7
by: tea-jay | last post by:
hello every body our teacher asks us to write this assiment it has 2 question i did write the first one but the other was really complicated 2 me coz our teacher doesn't know how to explain...
4
by: Madmartigan | last post by:
Hello I have attempted the source code from Chapter 4 in Accelerated C++ page 70 but keep getting the above error. I'm not sure whether it is in the way I have saved the header files or because my...
2
by: yalbizu | last post by:
#include <iostream> #include <string> #include <fstream> #include <iomanip> using namespace std; const int NO_OF_STUDENTS=20; struct studentType { string studentFName; string studentLName;
3
by: hanie | last post by:
a student wants to know his grade average for the semester. the grades are give in letter grades with numeric equivalents. develop a solution to calculate a grade average given the letter grades(the...
3
by: blamp | last post by:
I have completed most of the program I just cant get the letter grade to print from the void printGrade function.The output of the program should be: Line 1: Based on the course score, this...
9
tiktik
by: tiktik | last post by:
Hi... I am doing this simple Java program which displays a particular grade (A, B, C...) according to the mark entered. However I cannot arrange it in such a way that it displays "Invalid" if...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.