Solved

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

Posted on 2015-02-15
4
781 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 20

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

685 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