Hiding Elements in a Repeater

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'd like to hide a Hyperlink object in a repeater if the hyperlink is NULL. So,
<repeater id="rpt" runat="server">
<itemtemplate>
<%# DataBinder.Eval(Container.DataItem, "company") %> <br />
<asp:hyperlink id="lnk" navigateurl='<%# DataBinder.Eval(Container.DataItem,
"link") %>' imageurl="video.gif" runat="server" />
<itemtemplate>
</repeater>
This repeater will be bound to a Date Reader. If the link field is null,
then I'd like to make the hyperlink object invisible, to hide the image. Is
there any way to accomplish this?
Thanks,
 
Heres a solution to my problem:
Add the following to the hyperlink tag:

visible='<%# DataBinder.Eval(Container.DataItem, "link").ToString() != "" %>'
 
Your solution works, but I've found odd behavior in Visual C# .NET:
when I paste your solution into my .aspx page, necessary auto-generated
code disappears the .aspx.cs file. I had to paste this back into
InitializeComponent() to get my page to work:

this.Load += new System.EventHandler(this.Page_Load);
 
Thats very strange. I checked and that code is in all my code-behind pages.
im not sure why yours dissappeared. Although it wont be the first
unexplained anomoly to occur in VS.Net. Hehehe.
 
Back
Top