Discussion:
Repeater and Eval
Gabriel
2007-04-26 09:59:24 UTC
Permalink
Hello,


I have the code below. I'd like to add a "if" to display only the hyperlink
(the first) only when Url is not empty.

How can I do that ?

Regards,






<asp:Repeater runat="server" ID="menu"
DataSourceID="SiteMapDataSource1" EnableViewState="False">
<ItemTemplate>
<li>

<asp:HyperLink runat="server"
NavigateUrl='<%# Eval("Url") %>'><%# Eval("Title") %></asp:HyperLink>

<asp:Repeater runat="server" DataSource='<%#
((SiteMapNode) Container.DataItem).ChildNodes %>'>
<HeaderTemplate>
<ul>
</HeaderTemplate>

<ItemTemplate>
<li>
<asp:HyperLink runat="server"
NavigateUrl='<%# Eval("Url") %>'><%# Eval("Title") %></asp:HyperLink>
</li>
</ItemTemplate>

<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
</li>
</ItemTemplate>
</asp:Repeater>

===================================
This list is hosted by DevelopMentor® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Efran Cobisi
2007-04-26 10:12:16 UTC
Permalink
Gabriel,

Sticking with the declarative model, even if I am not a big fan of it,
you could set up the Visible property as you have done with other
properties, like NavigateUrl:

<asp:HyperLink runat="server" NavigateUrl='<%# Eval("Url") %>'
Visible='<%# !String.IsNullOrEmpty(Eval("Url")) %>'><%# Eval("Title")
%></asp:HyperLink>

HTH,

--
Efran Cobisi
http://www.cobisi.com
Post by Gabriel
Hello,
I have the code below. I'd like to add a "if" to display only the hyperlink
(the first) only when Url is not empty.
How can I do that ?
Regards,
<asp:Repeater runat="server" ID="menu"
DataSourceID="SiteMapDataSource1" EnableViewState="False">
<ItemTemplate>
<li>
<asp:HyperLink runat="server"
NavigateUrl='<%# Eval("Url") %>'><%# Eval("Title") %></asp:HyperLink>
<asp:Repeater runat="server"
DataSource='<%#
((SiteMapNode) Container.DataItem).ChildNodes %>'>
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<li>
<asp:HyperLink runat="server"
NavigateUrl='<%# Eval("Url") %>'><%# Eval("Title") %></asp:HyperLink>
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
</li>
</ItemTemplate>
</asp:Repeater>
===================================
This list is hosted by DevelopMentor® http://www.develop.com
View archives and manage your subscription(s) at
http://discuss.develop.com
===================================
This list is hosted by DevelopMentor® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Ryan Heath
2007-04-26 10:21:18 UTC
Permalink
<% if ( !string.IsNullOrEmpty( (string)Eval("Title"))) { %>
<asp:HyperLink runat="server" NavigateUrl='<%# Eval("Url") %>'><%#
Eval("Title") %></asp:HyperLink>
<% } %>

HTH
// Ryan
Post by Gabriel
Hello,
I have the code below. I'd like to add a "if" to display only the hyperlink
(the first) only when Url is not empty.
How can I do that ?
Regards,
<asp:Repeater runat="server" ID="menu"
DataSourceID="SiteMapDataSource1" EnableViewState="False">
<ItemTemplate>
<li>
<asp:HyperLink runat="server"
NavigateUrl='<%# Eval("Url") %>'><%# Eval("Title") %></asp:HyperLink>
<asp:Repeater runat="server" DataSource='<%#
((SiteMapNode) Container.DataItem).ChildNodes %>'>
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<li>
<asp:HyperLink runat="server"
NavigateUrl='<%# Eval("Url") %>'><%# Eval("Title") %></asp:HyperLink>
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
</li>
</ItemTemplate>
</asp:Repeater>
===================================
This list is hosted by DevelopMentor(r) http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com
===================================
This list is hosted by DevelopMentor® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Gabriel
2007-04-26 10:55:18 UTC
Permalink
Hello,

Sorry but your both answers not work. I have compilation error.

Regards,
Post by Ryan Heath
<% if ( !string.IsNullOrEmpty( (string)Eval("Title"))) { %>
<asp:HyperLink runat="server" NavigateUrl='<%# Eval("Url") %>'><%#
Eval("Title") %></asp:HyperLink>
<% } %>
HTH
// Ryan
Post by Gabriel
Hello,
I have the code below. I'd like to add a "if" to display only the
hyperlink
Post by Gabriel
(the first) only when Url is not empty.
How can I do that ?
Regards,
<asp:Repeater runat="server" ID="menu"
DataSourceID="SiteMapDataSource1" EnableViewState="False">
<ItemTemplate>
<li>
<asp:HyperLink runat="server"
NavigateUrl='<%# Eval("Url") %>'><%# Eval("Title") %></asp:HyperLink>
<asp:Repeater runat="server"
DataSource='<%#
Post by Gabriel
((SiteMapNode) Container.DataItem).ChildNodes %>'>
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<li>
<asp:HyperLink runat="server"
NavigateUrl='<%# Eval("Url") %>'><%# Eval("Title") %></asp:HyperLink>
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
</li>
</ItemTemplate>
</asp:Repeater>
===================================
This list is hosted by DevelopMentor(r) http://www.develop.com
View archives and manage your subscription(s) at
http://discuss.develop.com
===================================
This list is hosted by DevelopMentor(r) http://www.develop.com
View archives and manage your subscription(s) at
http://discuss.develop.com
===================================
This list is hosted by DevelopMentor® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Gabriel
2007-04-26 10:55:51 UTC
Permalink
Sorry but your both answers not work. I have compilation error.



It's the second hyperlink I have to hide not the first.

Regards,

===================================
This list is hosted by DevelopMentor® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Chris Anderson
2007-04-26 11:09:16 UTC
Permalink
Try :

<asp:HyperLink
runat="server"
NavigateUrl='<%# Eval("Url") %>'
Visible='<%# (!String.IsNullOrEmpty(Eval("Url"))).ToString() %>'
<%# Eval("Title") %></asp:HyperLink>


i.e. set the Visible property equal to "True" if the Url is not empty,
and "False" if it is.

===================================
This list is hosted by DevelopMentor� http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Gabriel
2007-04-26 11:29:39 UTC
Permalink
Post by Gabriel
<asp:HyperLink
runat="server"
NavigateUrl='<%# Eval("Url") %>'
Visible='<%# (!String.IsNullOrEmpty(Eval("Url"))).ToString() %>'
<%# Eval("Title") %></asp:HyperLink>
Not work :(.

It's the second hyperlink in the repeater I need to hide this section :


<ItemTemplate>
<li>
<asp:HyperLink runat="server"
NavigateUrl='<%# Eval("Url") %>'><%# Eval("Title") %></asp:HyperLink>
</li>
</ItemTemplate>


Regards,

===================================
This list is hosted by DevelopMentor® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Patrick Steele
2007-04-26 11:45:33 UTC
Permalink
1. "Not work" doesn't give us much information to help you.

2. People are giving you ideas on how to hide "a" hyperlink. We're
leaving it up to you to apply the knowledge to the second (or whatever)
hyperlink you need it on.

---
Patrick Steele
http://weblogs.asp.net/psteele


-----Original Message-----
From: Discussion of building .NET applications targeted for the Web
[mailto:DOTNET-***@DISCUSS.DEVELOP.COM] On Behalf Of Gabriel
Sent: Thursday, April 26, 2007 7:30 AM
To: DOTNET-***@DISCUSS.DEVELOP.COM
Subject: Re: [DOTNET-WEB] Repeater and Eval
Post by Gabriel
<asp:HyperLink
runat="server"
NavigateUrl='<%# Eval("Url") %>'
Visible='<%# (!String.IsNullOrEmpty(Eval("Url"))).ToString() %>'
<%# Eval("Title") %></asp:HyperLink>
Not work :(.

It's the second hyperlink in the repeater I need to hide this section :


<ItemTemplate>
<li>
<asp:HyperLink
runat="server" NavigateUrl='<%# Eval("Url") %>'><%# Eval("Title")
%></asp:HyperLink>
</li>
</ItemTemplate>


Regards,

===================================
This list is hosted by DevelopMentorR http://www.develop.com

View archives and manage your subscription(s) at
http://discuss.develop.com

===================================
This list is hosted by DevelopMentor� http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Gabriel
2007-04-26 11:50:56 UTC
Permalink
Post by Patrick Steele
1. "Not work" doesn't give us much information to help you.
Sorry "No code block allowed here"..

Regards,

===================================
This list is hosted by DevelopMentor® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Chris Anderson
2007-04-26 11:50:49 UTC
Permalink
Post by Patrick Steele
From: Discussion of building .NET applications targeted for the Web
Sent: 26 April 2007 12:31
Subject: Re: [DOTNET-WEB] Repeater and Eval
Post by Gabriel
<asp:HyperLink
runat="server"
NavigateUrl='<%# Eval("Url") %>'
Visible='<%# (!String.IsNullOrEmpty(Eval("Url"))).ToString() %>'
<%# Eval("Title") %></asp:HyperLink>
Not work :(.
It's the second hyperlink in the repeater I need to hide this section
<ItemTemplate>
<li>
<asp:HyperLink
runat="server"
NavigateUrl='<%# Eval("Url") %>'><%# Eval("Title") %></asp:HyperLink>
</li>
</ItemTemplate>
That's the hyperlink I (and I think everyone else that has responded) is
trying to hide.

You cannot hide an ItemTemplate (because it's just a template), so you
need to either hide the list item <li> or the hyperlink itself for a
specific bound item.

If you really only want to hide the hyperlink, replacing the hyperlink
with this works (I tested):

<asp:HyperLink
runat="server"
NavigateUrl='<%# Eval("Url") %>'
Visible='<%# (!String.IsNullOrEmpty((string)Eval("Url"))) %>'
Post by Patrick Steele
<%# Eval("Title") %>
</asp:HyperLink>

(I missed the cast to a string in my above code, which is why it
probably failed last time)


If you *actually* want the list item (the <li>)removed from the <ul>
list, then you need to use similar logic to hide the <li> tag:

<li
runat="server"
visible='<%# (!String.IsNullOrEmpty((string)Eval("Url"))) %>'>
<asp:HyperLink
runat="server"
NavigateUrl='<%# Eval("Url") %>'
Post by Patrick Steele
<%# Eval("Title") %> </asp:HyperLink>
</li>

===================================
This list is hosted by DevelopMentor� http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Loading...