Solved

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

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

770 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