I am making a html form and when the user submits the form an aspx
page will load to display the results of the form. I have 20 questions total with 5 radio buttons each. For some reason when I try to retrieve the selected radio buttons thru a for loop, it only displays one answer. What am I doing wrong?
I have tried changing the values in the for loop but it just seems to not be displaying correctly.
Here's the code for the aspx.cs
public void DisplayResults(double[] results)
{
try
{
int q = 1;
for (int i = 0; i <= 19; i++)
{
if (i == 0)
{
txtResults.Text = "Course Results";
if (results[i] == 1)
{
txtResults.Text += "Q" + q + ": Strongly Disagree";
}
else if (results[i] == 2)
{
txtResults.Text += "Q" + q + ": Disagree";
}
else if (results[i] == 3)
{
txtResults.Text += "Q" + q + ": Neutral";
}
else if (results[i] == 4)
{
txtResults.Text += "Q" + q + ": Agree";
}
else if (results[i] == 5)
{
txtResults.Text += "Q" + q + ": Strongly Agree ZERO";
}
}
else if (i == 11)
{
txtResults.Text = "Professor Results";
if (results[i] == 1)
{
txtResults.Text += "Q" + q + ": Strongly Disagree";
}
else if (results[i] == 2)
{
txtResults.Text += "Q" + q + ": Disagree";
}
else if (results[i] == 3)
{
txtResults.Text += "Q" + q + ": Neutral";
}
else if (results[i] == 4)
{
txtResults.Text += "Q" + q + ": Agree";
}
else if (results[i] == 5)
{
txtResults.Text += "Q" + q + ": Strongly Agree ELEVEN";
}
}
else
{
if (results[i] == 1)
{
txtResults.Text += "Q" + q + ": Strongly Disagree";
}
else if (results[i] == 2)
{
txtResults.Text += "Q" + q + ": Disagree";
}
else if (results[i] == 3)
{
txtResults.Text += "Q" + q + ": Neutral";
}
else if (results[i] == 4)
{
txtResults.Text += "Q" + q + ": Agree";
}
else if (results[i] == 5)
{
txtResults.Text += "Q" + q + ": Strongly Agree ELSE";
}
}
if (txtResults.Text == "")
{
throw new Exception();
}
}
}
catch (Exception e)
{
Console.Write(e.Message, "Error");
}
}
Here's the code for aspx
<fieldset>
<legend>Feedback Results</legend>
<asp:TextBox ID="txtResults" runat="server" TextMode="MultiLine" Width="100%" Height="500px"></asp:TextBox>
</fieldset>
Here's my html code
<h3>Please answer these questions to the best of your knowledge:</h3>
<fieldset>
<legend>Course Content (Organization, Clarity of Expectations/Directions, Balance/Appropriateness)</legend>
1. The course (or section) presented skills in a helpful sequence
<br />
<input type="radio" name="q1" value="5" />strongly agree
<input type="radio" name="q1" value="4" />agree
<input type="radio" name="q1" value="3" />neutral
<input type="radio" name="q1" value="2" />disagree
<input type="radio" name="q1" value="1" />strongly disagree
<br />
<br />
2. The course (or section) provided an appropriate balance between instruction and practice
<br />
<input type="radio" name="q2" value="5" />strongly agree
<input type="radio" name="q2" value="4" />agree
<input type="radio" name="q2" value="3" />neutral
<input type="radio" name="q2" value="2" />disagree
<input type="radio" name="q2" value="1" />strongly disagree
<br />
<br />
3. The course (or section) was appropriate for the stated level of the class
<br />
<input type="radio" name="q3" value="5" />strongly agree
<input type="radio" name="q3" value="4" />agree
<input type="radio" name="q3" value="3" />neutral
<input type="radio" name="q3" value="2" />disagree
<input type="radio" name="q3" value="1" />strongly disagree
<br />
<br />
4. The course (or section) was organized in a way that helped me learn
<br />
<input type="radio" name="q4" value="5" />strongly agree
<input type="radio" name="q4" value="4" />agree
<input type="radio" name="q4" value="3" />neutral
<input type="radio" name="q4" value="2" />disagree
<input type="radio" name="q4" value="1" />strongly disagree
<br />
<br />
5. The lab helped to complement the lectures
<br />
<input type="radio" name="q5" value="5" />strongly agree
<input type="radio" name="q5" value="4" />agree
<input type="radio" name="q5" value="3" />neutral
<input type="radio" name="q5" value="2" />disagree
<input type="radio" name="q5" value="1" />strongly disagree
<br />
<br />
6. The course (or section) provided a mixture of explanation and practice
<br />
<input type="radio" name="q6" value="5" />strongly agree
<input type="radio" name="q6" value="4" />agree
<input type="radio" name="q6" value="3" />neutral
<input type="radio" name="q6" value="2" />disagree
<input type="radio" name="q6" value="1" />strongly disagree
<br />
<br />
7. The course (or section) was effectively organized
<br />
<input type="radio" name="q7" value="5" />strongly agree
<input type="radio" name="q7" value="4" />agree
<input type="radio" name="q7" value="3" />neutral
<input type="radio" name="q7" value="2" />disagree
<input type="radio" name="q7" value="1" />strongly disagree
<br />
<br />
8. The course (or section) assignments and lectures usefully complemented each other
<br />
<input type="radio" name="q8" value="5" />strongly agree
<input type="radio" name="q8" value="4" />agree
<input type="radio" name="q8" value="3" />neutral
<input type="radio" name="q8" value="2" />disagree
<input type="radio" name="q8" value="1" />strongly disagree
<br />
<br />
9. The course (or section) instructions (including, manuals, handouts, etc.) were clear
<br />
<input type="radio" name="q9" value="5" />strongly agree
<input type="radio" name="q9" value="4" />agree
<input type="radio" name="q9" value="3" />neutral
<input type="radio" name="q9" value="2" />disagree
<input type="radio" name="q9" value="1" />strongly disagree
<br />
<br />
10. The course (or section) work helped me understand concepts more clearly
<br />
<input type="radio" name="q10" value="5" />strongly agree
<input type="radio" name="q10" value="4" />agree
<input type="radio" name="q10" value="3" />neutral
<input type="radio" name="q10" value="2" />disagree
<input type="radio" name="q10" value="1" />strongly disagree
<br />
<br />
11. Instructions for course (or section) materials (including manuals, handouts, etc.) were clear
<br />
<input type="radio" name="q11" value="5" />strongly agree
<input type="radio" name="q11" value="4" />agree
<input type="radio" name="q11" value="3" />neutral
<input type="radio" name="q11" value="2" />disagree
<input type="radio" name="q11" value="1" />strongly disagree
<br />
<br />
12. The lab complemented my understanding of the lectures
<br />
<input type="radio" name="q12" value="5" />strongly agree
<input type="radio" name="q12" value="4" />agree
<input type="radio" name="q12" value="3" />neutral
<input type="radio" name="q12" value="2" />disagree
<input type="radio" name="q12" value="1" />strongly disagree
</fieldset>
<br />
<br />
<fieldset>
<legend> Instructor Specific Questions</legend>
1. The instructor clearly presented the skills to be learned
<br />
<input type="radio" name="q13" value="5" />strongly agree
<input type="radio" name="q13" value="4" />agree
<input type="radio" name="q13" value="3" />neutral
<input type="radio" name="q13" value="2" />disagree
<input type="radio" name="q13" value="1" />strongly disagree
<br />
<br />
2. The instructor effectively presented concepts and techniques
<br />
<input type="radio" name="q14" value="5" />strongly agree
<input type="radio" name="q14" value="4" />agree
<input type="radio" name="q14" value="3" />neutral
<input type="radio" name="q14" value="2" />disagree
<input type="radio" name="q14" value="1" />strongly disagree
<br />
<br />
3. The instructor presented content in an organized manner
<br />
<input type="radio" name="q15" value="5" />strongly agree
<input type="radio" name="q15" value="4" />agree
<input type="radio" name="q15" value="3" />neutral
<input type="radio" name="q15" value="2" />disagree
<input type="radio" name="q15" value="1" />strongly disagree
<br />
<br />
4. The instructor effectively presented the tools (e.g. materials, skills, and techniques) needed
<br />
<input type="radio" name="q16" value="5" />strongly agree
<input type="radio" name="q16" value="4" />agree
<input type="radio" name="q16" value="3" />neutral
<input type="radio" name="q16" value="2" />disagree
<input type="radio" name="q16" value="1" />strongly disagree
<br />
<br />
5. The instructor explained concepts clearly
<br />
<input type="radio" name="q17" value="5" />strongly agree
<input type="radio" name="q17" value="4" />agree
<input type="radio" name="q17" value="3" />neutral
<input type="radio" name="q17" value="2" />disagree
<input type="radio" name="q17" value="1" />strongly disagree
<br />
<br />
6. The instructor made the elements of good writing clear
<br />
<input type="radio" name="q18" value="5" />strongly agree
<input type="radio" name="q18" value="4" />agree
<input type="radio" name="q18" value="3" />neutral
<input type="radio" name="q18" value="2" />disagree
<input type="radio" name="q18" value="1" />strongly disagree
<br />
<br />
7. The instructor clearly articulated the standards of performance for the course
<br />
<input type="radio" name="q19" value="5" />strongly agree
<input type="radio" name="q19" value="4" />agree
<input type="radio" name="q19" value="3" />neutral
<input type="radio" name="q19" value="2" />disagree
<input type="radio" name="q19" value="1" />strongly disagree
<br />
<br />
8. The instructor provided guidance for understanding course exercises
<br />
<input type="radio" name="q20" value="5" />strongly agree
<input type="radio" name="q20" value="4" />agree
<input type="radio" name="q20" value="3" />neutral
<input type="radio" name="q20" value="2" />disagree
<input type="radio" name="q20" value="1" />strongly disagree
</fieldset>
I want to be able to display each result for each question in the same multi-line textbox like so but it be split between courses and professor questions:
COURSES
Q1: Disagree
Q2: Neutral
Q3: Neutral
etc...
PROFESSOR
Q1: Disagree
Q2: Neutral
Q3: Neutral
etc...
First: It's because you've not incremented the q value,
Incorrect because q is always 1:
txtResults.Text = "Course Results";
if (results[i] == 1)
{
txtResults.Text += "Q" + q + ": Strongly Disagree";
}
Second, you've allowed the program to write for cases where i=0 and i=11
Full answer:
public void DisplayResults(double[] results)
{
try
{
for (int i = 0, q = 1; i <= 19; i++, q++)
{
if (i == 0)
{
txtResults.Text += "Course Results";
}
if (i == 11)
{
txtResults.Text += "Professor Results";
}
txtResults.Text += "Q" + q ": ";
if (results[i] == 1)
{
txtResults.Text +="Strongly Disagree";
}
else if (results[i] == 2)
{
txtResults.Text +="Disagree";
}
else if (results[i] == 3)
{
txtResults.Text +=": Neutral";
}
else if (results[i] == 4)
{
txtResults.Text +="Agree";
}
else if (results[i] == 5)
{
if(i == 0 )
txtResults.Text +="Strongly Agree ZERO";
else if(i == 11 )
txtResults.Text +="Strongly Agree ELEVEN";
else
txtResults.Text +="Strongly Agree";
}
}
}
catch (Exception e)
{
Console.Write(e.Message, "Error");
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.