>>Hi everybody,
>>
>>I have a variable that can be either 0 or NULL or some integer value. Is there a way to check for both conditions 0 and NULL without using OR condition (no LINQ, please, I want compatibility with .NET 2.0)
>>
>>I have currently
>>
>>(DataBinder.Eval(Container.DataItem, "SpouseID").ToString() != "") which works correctly for NULL, but doesn't work for 0.
>>
>>Thanks a lot in advance.
>
>I think I have an answer on my question.
>
http://weblogs.asp.net/scottgu/archive/2007/09/20/the-new-c-null-coalescing-operator-and-using-it-with-linq.aspxSomehow I can not make this expression correctly, may be someone can help?
I have currently
<%# (DataBinder.Eval(Container.DataItem, "SpouseID").ToString() != "")
? Eval("SpouseID", "<a href=\"javascript:void(0)\"
onClick=\"openPeopleID('{0}')\">Spouse's Information</a>") :
"<a href=\"javascript:void(0)\" onClick=\"openCreateID('motherName','AddressInfoRegular')\">
Enter Spouse's Info first</a>"%></span>
It works correctly if SpouseID is null, e.g. it goes to the Enter case. However, it doesn't work for the case it's a 0.
Is there a simple check for both "0" and ""? Or how to implement null coalesce operator for this complex case?
Thanks a lot in advance.
If it's not broken, fix it until it is.
My Blog