Click here to Skip to main content
15,923,909 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have to hide/show a link based upon a value coming from database, if value from db is '0' then I have to display href link else hide it.

It tried to use if condition, but it does not work with "Eval".

Thanks in advance
Posted

1 solution

Below code should work -

<a href="#" style="visibility: '<%#Eval("Valid")=="0" ? "hidden" :"visible" %>'">HyperLink</a>
 
Share this answer
 
Comments
sam7one 30-Sep-13 10:24am    
It does not work, if I use it with LinkButton control, it throws error "Cannot convert type 'string' to 'bool'".

If used HTML anchor tag, it gives error "DataBinding: 'System.Data.Common.DataRecordInternal' does not contain a property with the name 'Valid'."
Madhu Nair 1-Oct-13 0:15am    
Use like given below for Link button control. Please not that "Valid" is the field name you are bounding to the control & not any property

'<%#Eval("Valid")==null ? false :(object) Convert.ToBoolean(Eval("Valid"))

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900