Wednesday, April 18, 2012

Asp.net: how to compare DataBinder.Eval with a member variable?

I am trying to do this in a repeater:



<%# Iif((int)DataBinder.Eval(Container.DataItem, "Id") == SelectedJobDefId, "blue", "red")%>


Problem is that the member property only evaluates if this syntax is used:



<%= SelectedJobDefId %>


DataBinder.Eval() only works if the hash symbol is used.



As a test, I tried this:



  <%= SelectedJobDefId %>
<%# DataBinder.Eval(Container.DataItem, "Id") + " " + SelectedJobDefId %>


The first SelectedJobDefId stays correct as I switch rows (LinkButton event).
The DataBinder part is correct for each row.
The 2nd output of SelectedJobDefId is always "1".



How can I compare these two values?





No comments:

Post a Comment