I am getting the following error
Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
but all I am trying to do is inside a ASP.NET REPEATER Control
<% if ( Eval("Message").ToString() == HttpContext.Current.Profile.UserName) %>
<% { %>
<asp:ImageButton runat="server" etc.... />
<% } %>
The syntax is
<%# Eval("...") %>
You could do something like
<asp:ImageButton Visible='<%# ShowImg(Eval(Container.DataItem,"Message")) %>' />
and in your codebehind:
boolean ShowImg(string msg)
{
return (msg == HttpContext.Current.Profile.UserName);
}
An alternative is this:
<asp:ImageButton runat="server" Visible='<%# Eval("Message").ToString() == HttpContext.Current.Profile.UserName %>' />
Then there is no need for code behind.
Its too late but i would like to answer it in my way, what i used to achieve it:
<%# Eval("Message").toString()== HttpContext.Current.Profile.UserName)?"<asp:ImageButton runat="server" etc.... />" :""%>
Now this will only show image button if Message is equal to username.
This might help any one else in same situation.
In my situation i needed to check null and empty string...so i implemented like this below:
<%# Eval("DateString")!= null && Eval("DateString")!= ""? "<span class='date'>"+Eval("DateString") + "</span>":"" %>
Thanks
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With