title: ASP.NET: Using Eval in an if statement
body: <p>I have a repeater. In the past, each item in the repeater had an associated text box. But, now I added an attribute to the repeated item that needs to specify if a text box, larger text box, or check box is used for that item.</p>
  
  <p>Here is what my aspx code looks like:</p>
  
  <pre><code>&lt;%if (Eval("DisplayType") == "LargeBox") { %&gt;
      &lt;asp:TextBox ID="largeBoxAnswer" Rows="8" runat="server" Width="200" MaxLength="2000" EvaluationQuestionID='&lt;%# Eval("EvaluationQuestionId") %&gt;' /&gt;
      &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="largeBoxAnswer" Display="dynamic" Font-Bold="true" ErrorMessage="*" /&gt;
  &lt;%} %&gt;
  &lt;%else if (Eval("DisplayType") == "CheckBox") { %&gt;
      &lt;asp:TextBox ID="checkBoxAnswer" runat="server" Width="200" MaxLength="100" EvaluationQuestionID='&lt;%# Eval("EvaluationQuestionId") %&gt;' /&gt;
      &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="checkBoxAnswer" Display="dynamic" Font-Bold="true" ErrorMessage="*" /&gt;
  &lt;%} %&gt;
  &lt;%else { %&gt;
      &lt;asp:TextBox ID="txtAnswer" runat="server" Width="200" MaxLength="100" EvaluationQuestionID='&lt;%# Eval("EvaluationQuestionId") %&gt;' /&gt;
      &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtAnswer" Display="dynamic" Font-Bold="true" ErrorMessage="*" /&gt;
  &lt;%} %&gt;
  </code></pre>
  
  <p>This is not working and I get the following error:
  <code>Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.</code></p>
  
  <p>I found quite a bit about this error, but nothing that really helped with this particular issue. </p>
  
  <p>Am I even going about doing something like this the correct way? I am not super experienced with asp.net, so I am open to a different approach to this issue. If this is the best way, how do I move the logic to the code behind so this works properly?</p>