Click here to Skip to main content
15,906,467 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<% if(Eval("img_url") != "")
           {%>
            <img alt="<%#Eval("name")%>" title="<%#Eval("name")%>" src='../img/avatars/<%#Eval("avatar_url")%>' style="width: 80px; height: 80px">
            <%}
           else
           {%>
            <img alt="<%#Eval("name")%>" title="<%#Eval("name")%>" src="../img/blank.gif" style="width: 80px; height: 80px">
            <%} %>

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

Please help me how can i solve this

Thanks in advance
Posted

use following
C#
<%# DataBinder.Eval(Container.DataItem, "name") %>
 
Share this answer
 
Comments
rahul dev123 2-Jun-11 8:51am    
I have no problem in name field. Its problem on if if(Eval("img_url") != "" so where i used this code
Insted of double Quotes use singleQuotes

XML
<% if(Eval("img_url") != "")
           {%>
            <img alt='<%#Eval("name")%>' title='<%#Eval("name")%>' src='../img/avatars/<%#Eval("avatar_url")%>' style="width: 80px; height: 80px">
            <%}
           else
           {%>
            <img alt='<%#Eval("name")%>' title='<%#Eval("name")%>' src="../img/blank.gif" style="width: 80px; height: 80px">
            <%} %>
 
Share this answer
 
Comments
rahul dev123 3-Jun-11 1:40am    
Same error

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