I was wonder if there is a better way of writing this code.
<%#Eval("hasAccess").Equals(true) ? "<a href='/CaseActivities.aspx?" + Eval("caseURL") + "'>" + Eval("caseName") + "</a>" : Eval("caseName")%>
I tried <% If (Eval(“hasAccess”) … but asp.net doesnt like that 🙂
I was hoping for something like
<% If Eval("hasAccess") %>
do stuff ..
<% else %>
do other stuff.
But when using the Eval with IF it get messy .. any thoughts?
You should almost certainly be doing this in code behind, not in scriptlets. In the case of data binding there are a few options:
Rather than performing these operations as a part of the data binding, change the underlying data source before binding it so that the data binding itself only takes the value as is.
Add a method to the code behind that takes the column and returns the proper value, that way the data binding method just needs to eval a call to that method passing this column.
Don’t do the data binding in markup if it is going to be complex; use data binding events in code behind (when available).
Those are listed in the order of preference in which you should try to use them.