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
- string studentAnswer;
- string lecturerAnswer;
- int Grade = 0;
- int i = 1;
- public void Button1_Click(object sender, EventArgs e)
- {
- DataSet1TableAdapters.QuestionsTTableAdapter adapter = new DataSet1TableAdapters.QuestionsTTableAdapter();
- DataSet1.QuestionsTDataTable questions = adapter.GetData();
- DataSet1.QuestionsTRow rowT = questions[i];
- foreach ( GridViewRow row in GridView1.Rows )
- {
- lecturerAnswer = rowT.Answers;
- i++;
- RadioButtonList radiolist = (RadioButtonList)row.FindControl("radlist");
- if (radiolist != null )
- {
- foreach (ListItem litem in radiolist.Items)
- {
- if (litem.Selected)
- {
- studentAnswer = radiolist.SelectedValue.ToString();
- }
- }
- }
- if (studentAnswer == lecturerAnswer)
- {
- Grade++;
- }
- else
- {
- Grade= Grade + 0;
- }
- }
- Label1.Text = "You have Scored " + Grade;
- }