Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   The name 'Container' does not exist in the current context (http://www.velocityreviews.com/forums/t599522-the-name-container-does-not-exist-in-the-current-context.html)

Peter Morris 03-17-2008 04:27 PM

The name 'Container' does not exist in the current context
 
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.Data Item,
"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 03-17-2008 04:51 PM

RE: The name 'Container' does not exist in the current context
 
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)


"Peter Morris" wrote:

> 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.Data Item,
> "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
>
>
>


Peter Morris 03-17-2008 05:57 PM

Re: The name 'Container' does not exist in the current context
 
> 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?




All times are GMT. The time now is 05:32 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.