I have a string array of survey responses called "answers".
string[] answers = new string[10] {"Y", "Y", "N", "Y", "N", "Y", "N", "Y", "N", "Y"};
I know that if I create a new string for each index like so:
string answer1 = answers[0]
I can put <%=answer1%> in the HTML/ASPX page and it will display "Y" as it should. However, my array will have upwards of 50 items (although the number of items won't change).
One way to do it is creating 50 variables and referencing them individually but let's be honest..
Here's my <body>
;) (or what I want it to look like, at least.)
<body>
<div class="container">
<asp:Panel ID="pnlResults1" runat="server">
<div class="section z-depth-2 blue-grey lighten-5">
<table style="width: 25%" align="center">
<tr>
<td><b>Question 1:</b></td>
<td><%=answer1%></td>
</tr>
<tr>
<td><b>Question 2</b></td>
<td><%=answer2%></td>
</tr>
<tr>
<td><b>Question 3</b></td>
<td><%=question3%></td>
</tr>
<tr>
<td><b>Question 4</b></td>
<td><%=question4%></td>
</tr>
<tr>
<td><b>Question 5</b></td>
<td><%=question5%></td>
</tr>
<tr>
<td><b>Question 6</b></td>
<td><%=question6%></td>
</tr>
</table>
</div>
</asp:Panel>
</div>
..and the table rows will keep counting. Basically, I want to display my 50+ survey responses in a table without having to create a string for each array index.
I was thinking of creating text boxes for the answers in html/aspx and using a foreach loop to go through each one and adding answers while iterating through answers[], but I'm not sure how I would iterate through the answers.
Something like (pseudocode)
int counter = 0;
foreach(Control c in Panel){
if(c is Text)
Text.setText(answers[counter]);
counter++;
}
Any help would be appreciated. Thanks!