Solved

Hide hyperlink is asp.net page if navigate URL is null

Posted on 2015-02-15
4
688 Views
Last Modified: 2015-02-16
I have several hyperlinks on a asp.net web form that are getting the navigate URL value by using databinding.   I have no problem with displaying the links with the URL.    If no problem with navigate url value is returned for a hyperlink but I no value is return I want to hind the link by setting the visible property to false.   I am not sure how to do it.

Here is how I am getting the navigate URL value:

 <asp:HyperLink ID="HyperLink1" Visible="true" NavigateUrl='<%# DataBinder.Eval(Container.DataItem, "article_url")%>' runat="server">Click here for more information</asp:HyperLink>
                                 
Any help would be appreciated.

Thanks
0
Comment
Question by:Mike_Stevens
4 Comments
 
LVL 19

Expert Comment

by:Daniel Van Der Werken
ID: 40611222
This is how I'd do it. First, I'd add an override for the SaveStateComplete event in my code behind.

Then, in this event, I'd check to see if the value for the NavigateUrl for that element is string.Emtpy or null. If it is, then set the element to Visible = false.
0
 
LVL 8

Expert Comment

by:Naitik Gamit
ID: 40611903
look at this link,conversation how to hide hyperlink if data is null

http://stackoverflow.com/questions/19059859/hide-hyperlink-if-data-is-null

hope this will help you to solve the problem.
0
 
LVL 14

Accepted Solution

by:
Lokesh B R earned 500 total points
ID: 40612036
Hi,

You hide like this.

 <asp:HyperLink ID="HyperLink1" NavigateUrl='<%# DataBinder.Eval(Container.DataItem, "article_url")%>' runat="server"
  Visible='<%# DataBinder.Eval(Container.DataItem, "article_url")!= null ? true : false  %>'>Click here for more information</asp:HyperLink>

Open in new window

0
 

Author Comment

by:Mike_Stevens
ID: 40612724
Lokesh.....your example causes syntax errors.  

it runs a 'syntax error' and Error 11      'null' is not declared. 'Null' constant is no longer supported; use 'System.DBNull' instead.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 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

14 Experts available now in Live!

Get 1:1 Help Now