Question

<asp:Repeater ID="rptEntries" runat="server" DataSourceID="dsEntries">
   <ItemTemplate>
      <%
         if (Convert.ToInt16(Eval("entryWinner")) == 1)
         {
      %>
            <%# "<div class=\"imgThumb draggable\" style=\"background-image:url('uploads/"
               + Eval("entryImagename") + "');\" data-id=\"" + Eval("pk_entryId")
               + "\"></div>"
            %>
      <%
          }else{
      %>
            <%# "<div class=\"imgThumb draggable\" style=\"background-image:url('uploads/"
                + Eval("entryImagename") + "'); filter: grayscale(100%);\" data-id=\""
                + Eval("pk_entryId") + "\"></div>"
            %>
      <%
           }
      %>
   </ItemTemplate>
</asp:Repeater>

I want to check te value from entryWinner before displaying, but it gives teh following error:

Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.

Was it helpful?

Solution

You may try something like that :

<asp:Repeater ID="rptEntries" runat="server" DataSourceID="dsEntries">
   <ItemTemplate>
            <%# String.Format("<div class=\"imgThumb draggable\" style=\"background-image:url('uploads/{0}');{1}\"  data-id=\"{2}\"></div>"
,Eval("entryImagename")
,(Convert.ToInt16(Eval("entryWinner")) == 1)?"":" filter: grayscale(100%);",Eval("pk_entryId"))%>
       </ItemTemplate>

</asp:Repeater>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top