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
bruce barker - 17 Mar 2008 17:51 GMT
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)
> I have an ASP:Repeater which shows Title, DateCreated, State
>
[quoted text clipped - 35 lines]
>
> Pete
Peter Morris - 17 Mar 2008 18:57 GMT
> with serverside code blocks (<% %>) which must be statements. code blocks
> 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?