views:

724

answers:

7

Hi, am having trouble with visible attribute of an asp.net panel. Basically I have a page that calls a database table and returns the results in a detailsview. However, some of the values that are returned are null and if so I need to hide the image thats next to it.

I am using a panel to determine whether to hide or show the image but am having trouble with the statement:

visible='<%# Eval("addr1") <> DBNull.Value %>'

I have tried these as well:

visible='<%# Eval("addr1") <> DBNull.Value %>'

visible='<%# IIf(Eval("addr1") Is DbNull.Value, "False","True") %>'

When I use these I get the error:

Compiler Error Message: CS1026: ) expected

Any help on what the syntax should be would be great.

Thanks

+2  A: 

I hate Databinding (for many reason, including this), Whenever I have an overly complex expression to bind to. I alawys declare it in the code behind and call on it to do the dirty work.

Something like

> visible='<%# GetIsVisible(Eval("addr1"))  %>'

Then you define your 'GetIsVisible' method to take a single object as a parameter. I'll leave that up to you, since you are using VB and I'll surely butcher it.

Edit: Just noticed you say you are using C# If its in C# you'll need to use the != operator, there is no <> operator in C#.

> visible='<%# Eval("addr1") <> DBNull.Value %>'

needs to be something like

> visible='<%# Eval("addr1") != DBNull.Value %>'

Also I would prob just use Convert.IsDBNull

> visible='<%# !Convert.IsDBNull(Eval("addr1")) %>'
Greg Dean
A: 

Try: visible='<%# (Eval("addr1") is DbNull.Value? "False":"True") %>'

the proper syntax for iif is (condition?if true this value : if false this value) assuming your using c#

JoshBerke
A: 

Erm...

Does this work?

visible='<%= IIf(Eval("addr1") Is DbNull.Value, "False","True") %>'

Or do you in fact have a semicolon at the end, like this (you shouldn't have BTW)

visible='<%# IIf(Eval("addr1") Is DbNull.Value, "False","True"); %>'
Christopher Edwards
"False" and "True" are strings. Visible wants a Boolean, so you'd leave off the quotes (of course, Iif returns an object, so you'd probably have to cast as well).
Mark Brackett
A: 

More stabs in the dark, try this

visible="<%# IIf(Eval('addr1') Is DbNull.Value, 'False','True') %>"
Christopher Edwards
+6  A: 

Your syntax says VB.NET, but you're compiler says C# (the CS* compiler error). Since I trust your compiler more:

Visible='<%# Eval("addr1") != DBNull.Value %>'
Mark Brackett
A: 

I have tried with and without comma, same error recieved. The page and website is all in C#

Thanks - I will try what you guys have suggested

A: 

Sorry for bringing an old thread back up, just wanted to say:

visible='<%# !Convert.IsDBNull(Eval("addr1")) %>'

this worked - LEGEND

thanks all