Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
2.00/5 (4 votes)
See more:
Please check this code, I need to declare this if and else in source code but it shown error like invalid expression term if

XML
<%#if(Eval("a_comment_counter")>0){%> <a href="/KB/answers/a_comments.aspx"?a_id=<%# Eval("a_id")%>"><%# Eval("a_comment_counter")%>
        comments</a> | <%} else {%><i>0 comments</i>

please any one help me.
Thanks in advance

if i declare condition like this but also the same problem


XML
<%#if(Eval("a_comment_counter")!=null){%> <a href="/KB/answers/a_comments.aspx"?a_id=<%# Eval("a_id")%>"><%# Eval("a_comment_counter")%>
        comments</a> | <%} else {%><i>0 comments</i>
Posted
Updated 3-Jun-11 2:21am
v2
Comments
Tech Code Freak 7-Jun-11 10:13am    
Just let everyone know whether you have got the solution and if Yes, then WHAT is IT?
If it is from one of these solutions, then just Accept them!

You cant use if-else construct in Eval function. Instead, you can use the syntax in this link which also acts as it were if-else. You can get your solution from here. It is Straight forward, clear and easy.Solution[^]
 
Share this answer
 
If you look at the documentation you see DataBinder.Eval returns an Object. Your if statement is trying to compare an Object and an integer, which can't be resolved. Try casting the left side to an integer or making the right side a string.
 
Share this answer
 
Comments
rahul dev123 3-Jun-11 8:17am    
yes but i declare it also !=null but it same problem.
remove # before if and then try. Or try like,-
<%if(%><%#Eval("a_comment_counter")%><%>0){
 
Share this answer
 
v2
Comments
rahul dev123 3-Jun-11 8:23am    
After remove # it shown error like:
Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
can you help me
Prasanta_Prince 3-Jun-11 8:24am    
try like that now..
rahul dev123 3-Jun-11 8:30am    
No this line is shown error
hey you can check this link[^], may find your solution
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900