Conditional output in Repeater?

P

Peter Morris

<ItemTemplate>
<tr class="DataListStyle">
<td><%# Html.Encode((string)DataBinder.Eval(Container.DataItem, "Title"))
%></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") %>" onclick="return
confirm('Re-publish this advert?');">
Publish</a>
<% } %>
<% if ((bool)Eval("CanWithdraw")) { %>
<a href="/Advert/Withdraw/<%# Eval("ID") %>" onclick="return
confirm('Withdraw this advert?');">
Withdraw</a>
<% } %>
</td>
</tr>
</ItemTemplate>


Can someone please tell me how I am supposed to implement the <% if %>
statements in the above markup? I am using the Web Extensions so I don't
have a <form runat="server">. This is annoying me :) Surely it should be
simple enough to output different HTML depending on a boolean?



Thanks

Pete
 
P

Peter Morris

The question was how do I do the "if" part?

I can't get hold of CanWithdraw for the current item. Container.DataItem
throws an exception that there is no Container.


Pete
 
B

bruce barker

you put the if in the methods GetUrl, etc.

in a repeator only binding expressions have access to the dataitem.


-- bruce (sqlwork.com)
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top