The name 'Container' does not exist in the current context

P

Peter Morris

I have an ASP:Repeater which shows Title, DateCreated, State

In addition I want two extra columns in my table

01: Modify (this works)
02: Publish or Withdraw depending on Item.CanPublish or Item.CanWithdraw

<tr class="DataListStyle">
<td><%# Html.Encode((string)DataBinder.Eval(Container.DataItem,
"Title")) %></td>
<td><%# DataBinder.Eval(Container.DataItem, "DateCreated") %></td>
<td><%# DataBinder.Eval(Container.DataItem, "State") %></td>
<td><a href="/Advert/Modify/<%# Eval("ID") %>">Modify</a></td>
<td>
<% if ((bool)DataBinder.Eval(Container.DataItem, "CanPublish")) { %>
<a href="/Advert/Publish/<%# Eval("ID") %>">Publish</a>
<% } %>
<% if ((bool)DataBinder.Eval(Container.DataItem, "CanWithdraw")) { %>
<a href="/Advert/Withdraw/<%# Eval("ID") %>">Witdraw</a>
<% } %>
</td>
</tr>

ERROR: CS0103: The name 'Container' does not exist in the current context


If instead I use the following

<% if ((bool)Eval("CanPublish")) { %>

I get the error

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


So, how do I achieve this?


Thanks

Pete
 
B

bruce barker

you are confusing databinding expressions (<%# %>) which must be an
expression, becuase it generates the code:

value = expression

with serverside code blocks (<% %>) which must be statements. code blocks do
not have a binding context.


-- bruce (sqlwork.com)
 
P

Peter Morris

with serverside code blocks ( said:
do
not have a binding context.

So how do I get the property value of the current object being databound? I
need to know if CurrentItem.CanPublish. Surely this is not impossible?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top