Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / March 2008

Tip: Looking for answers? Try searching our database.

Conditional output in Repeater?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Peter Morris - 19 Mar 2008 16:07 GMT
<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
sloan - 19 Mar 2008 16:15 GMT
See this post for an idea:

http://groups.google.com/group/microsoft.public.dotnet.general/msg/9738c9b0c5f2412f

> <ItemTemplate>
> <tr class="DataListStyle">
[quoted text clipped - 24 lines]
>
> Pete
Peter Morris - 19 Mar 2008 17:34 GMT
Good idea, I will try that, thanks!
bruce barker - 19 Mar 2008 16:48 GMT
write support functions, and call them:

<td>
   <a href="<%# GetUrl(Container.DataItem)%>"
        onclick="<%# GetClientClick(Container.DataItem)%>"
   >
   <%# GetText(Container.DataItem)%>
  </a>
 </td>

-- bruce (sqlwork.com)

> <ItemTemplate>
>  <tr class="DataListStyle">
[quoted text clipped - 24 lines]
>
> Pete
Peter Morris - 19 Mar 2008 17:31 GMT
The question was how do I do the "if" part?

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

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

Pete
bruce barker - 19 Mar 2008 18:11 GMT
you put the if in the methods GetUrl, etc.

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

-- bruce (sqlwork.com)

> The question was how do I do the "if" part?
>
[quoted text clipped - 4 lines]
>
> Pete

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.