Note that there are some explanatory texts on larger screens.

plurals
  1. PODuplicate list items even when using 'new' keyword
    primarykey
    data
    text
    <p>Sorry for asking such a vague question, i'm new to using C# / ASP.NET. When creating randomly generated questions, and storing the question objects within a list through the use of a for loop the same / duplicate question is showing up when I output the questions. I've inspected the list of questions with the debugger, and it shows 10 of the same object.</p> <p><strong>Server-side C# Used to populate the list of questions:</strong></p> <pre><code>private void Populate() { __NumberOfQuestions = 10; __Questions = new List&lt;Question&gt;(__NumberOfQuestions); for (int i = 0; i &lt; __NumberOfQuestions; i++) { __Questions.Add(new Question()); } QuestionList.DataSource = __Questions; QuestionList.DataBind(); } </code></pre> <p>Question class is avaialable here: <a href="http://pastebin.com/mEArQFHh" rel="nofollow">http://pastebin.com/mEArQFHh</a></p> <p><strong>ASP Code used to add the questions to the page:</strong></p> <pre><code> &lt;asp:Repeater ID="QuestionList" runat="server"&gt; &lt;ItemTemplate&gt; &lt;tr&gt; &lt;td&gt;&lt;%#DataBinder.Eval(Container.DataItem,"__LeftOperand")%&gt;&lt;/td&gt; &lt;td&gt;&lt;%#DataBinder.Eval(Container.DataItem,"__Operator")%&gt;&lt;/td&gt; &lt;td&gt;&lt;%#DataBinder.Eval(Container.DataItem,"__RightOperand")%&gt;&lt;/td&gt; &lt;td&gt;&lt;%#DataBinder.Eval(Container.DataItem,"__Answer")%&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/ItemTemplate&gt; &lt;/asp:Repeater&gt; </code></pre> <p>Output:</p> <p>9 SUBTRACT 6 3 9 SUBTRACT 6 3 9 SUBTRACT 6 3 9 SUBTRACT 6 3 9 SUBTRACT 6 3 9 SUBTRACT 6 3 9 SUBTRACT 6 3 9 SUBTRACT 6 3 9 SUBTRACT 6 3 9 SUBTRACT 6 3</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload