views:

368

answers:

2

Hey

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.... />
<% } %>
A: 

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)
{
     if (msg == HttpContext.Current.Profile.UserName)
           return true;
      else
           return false;
}
Steve
nice, I like that solution but what is Container.DataItem. While searching for an answer online I came across it also but cant seem to reference it in my projectthanks for the response
Dan
Cool that worked... i used the following<asp:ImageButton Visible ='<%# ShowImg(Eval("Message").ToString()) %>'
Dan
Yep, you can leave out the Container.DataItem, see http://msdn.microsoft.com/en-us/library/system.web.ui.databinder.eval.aspx
Steve
A: 

An alternative is this:

<asp:ImageButton runat="server" Visible='<%# Eval("Message").ToString() == HttpContext.Current.Profile.UserName %>' />

Then there is no need for code behind.

Jen