Solved

Repeater item if statement

Posted on 2008-06-16
9
716 Views
Last Modified: 2011-10-19
Hi,

I currently have a repeater item, that displays a text box and then a description of an item next to it with a link.  not ll of the items have a link though, so I need to create an if statement in the repeater to oly show the link version if the database field url is not null.  all my attempts so far have not worked.  here is the code for the basic link.  any help/guidance is appreciated.  all my attempts have ended with the Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control. errer.

The area in question is simply the url string link.

td><asp:TextBox ID=txtBox Width=50 CssClass="CenterItem" runat=server ></asp:TextBox> <asp:HiddenField ID="hdnID" Value=<%# Eval("ID").ToString() %> runat=server /></td>

                                            <td><a href="<%# Eval("url").ToString() %>"><%# Eval("title").ToString() %></a> - <%# Eval("NumPerBox").ToString() %> per box

                                                <asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="txtBox" MinimumValue="0" MaximumValue="1500" ErrorMessage="Number must be between 0 and 1500."></asp:RangeValidator></td>

Open in new window

0
Comment
Question by:fwong1
  • 5
  • 4
9 Comments
 
LVL 22

Expert Comment

by:prairiedog
Comment Utility
You can use Label to display URL like this:
<td><asp:Label ID ="lblURL" runat="server"><a href='<%# Eval("url").ToString() %>'><%# Eval("title").ToString() %></a></asp:Label></td>

Open in new window

0
 

Author Comment

by:fwong1
Comment Utility
That will shorten my code somewhat, but I am not following how that will help creating an if statement to make the title not a url if the database has no url value?
0
 
LVL 22

Expert Comment

by:prairiedog
Comment Utility
Have you tried that code yet? If the database has no URL value, no hyperlink will be created at all, so you do not need a if statement.
0
 

Author Comment

by:fwong1
Comment Utility
When I place the code in it does the same as mine did before.  I creates a blank link, that if clicked reloads the page back to the first view...
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 22

Expert Comment

by:prairiedog
Comment Utility
>>>I creates a blank link
Are you sure you placed my code in the right place? You cannot use <a> in your case, but you have to use Label and then assign a "<a hre...." string to the label. If Eval("url") is empty, then no link will be created. See my attached screen shot of a repeater using Northwind's Suppliers table.
One thing you need to keep in mind is that the URL needs to be a full URL if the link is for an external site, for example, "http://www.google.com", instead of "www.google.com".
2008-06-17-110014.jpg
0
 

Author Comment

by:fwong1
Comment Utility
First, thanks for the help.  I'm going to show you 2 screen prints...

This one here is what I need,  this is what I could do with the old ASP... I am upgrading everything to the ASP .ET 2.0, but I am stuck here....
1.jpg
0
 

Author Comment

by:fwong1
Comment Utility
And here is what I am getting
2.jpg
0
 
LVL 22

Expert Comment

by:prairiedog
Comment Utility
This is not what you asked in your question, though.
0
 

Accepted Solution

by:
fwong1 earned 0 total points
Comment Utility
Well, I was trying to get that across.  aparently I failed on that.  

I ended up creating 2 labels, one with the link, one without, and then I created 2 functions each a boolean function to decide which label to make visible.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now