Hiding Elements in a Repeater

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,
 
G

Guest

Heres a solution to my problem:
Add the following to the hyperlink tag:

visible='<%# DataBinder.Eval(Container.DataItem, "link").ToString() != "" %>'
 
K

Kevin

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);
 
G

Guest

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.
 

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

Top