Avatar of Spike
Spike
 asked on

Populating a gridview from an SQL using an outerjoin and ISNULL

I'm using an outerjoin with ISNULL as follows to populate a gridview on a webpage:

SELECT id,thing1,ISNULL(valid, 0)  as Valid
FROM things as d  left OUTER JOIN thing2 r  ON d.ID=r.parentThingID  
WHERE d.ID =1
 
Which returns the correct results (thanks guys!)

but

when I try to populate the grridview, the checkboxes fail to "check" based on the value in valid:

i.e. Checked='<%# Convert.ToBoolean(Eval("Valid")) %>'/>

The check box gets populated fine if I'm just using a straight queary without using the ISNULL. (where none of the values are null).

Cheers
Web DevelopmentMicrosoft SQL Server 2008

Avatar of undefined
Last Comment
Spike

8/22/2022 - Mon
Pratima

Not sure why its not working for you

try this query , Instade of Null use Case

SELECT id,thing1,
Case When valid = 1 then 'True' else 'False' End as Valid
ISNULL(valid, 0)  as Valid
FROM things as d  left OUTER JOIN thing2 r  ON d.ID=r.parentThingID  
WHERE d.ID =1
ASKER CERTIFIED SOLUTION
Pratima

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Spike

ASKER
It wasn't working for me as I'm an idiot!
I had linked the wrong IDs and hence it was always null.
You can have the points for at least trying!
Cheers!
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck