Categories
asp.net eval repeater

Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control

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);
}