Convert to Yes/No and Empty is Null
-
How can I handle Null and apply empty string if Null? <%# IIf(Boolean.Parse(Eval("IsReferralRequired").ToString.Trim()), "Yes", "No")%>
I think when you create a boolean, it always defaults to 0 or false Same with an integer, it defaults to 0 So if this is true, you just chack for true or 1 That's a tenary operator you wrote there in your code example. So you check for 1 value like true, and return either "Yes" or "No" depending on the value. so in c# https://msdn.microsoft.com/en-us/library/ty67wk28.aspx[^] And vb it's http://blog.dmbcllc.com/the-ternary-operator-in-vbnet/[^]
-
How can I handle Null and apply empty string if Null? <%# IIf(Boolean.Parse(Eval("IsReferralRequired").ToString.Trim()), "Yes", "No")%>
Perhaps, simply by checking the value to be null or not.
if(variable == null) {
variable = String.Empty; // provided variable is string type
}You can also set the
String.Empty
as the default value (value at the declaration stage), and then inside the script-based area you can alter the values.The shit I complain about It's like there ain't a cloud in the sky and it's raining out - Eminem ~! Firewall !~
-
Perhaps, simply by checking the value to be null or not.
if(variable == null) {
variable = String.Empty; // provided variable is string type
}You can also set the
String.Empty
as the default value (value at the declaration stage), and then inside the script-based area you can alter the values.The shit I complain about It's like there ain't a cloud in the sky and it's raining out - Eminem ~! Firewall !~
here is what I come up with however its replacing DBNull with 'No'. Instead I need to do an empty string. Please help
<%# IIf(IsDBNull(DataBinder.Eval(Container.DataItem, "IsReferralRequired")) OrElse String.IsNullOrEmpty(DataBinder.Eval(Container.DataItem, "IsReferralRequired")) OrElse (Convert.ToBoolean(Eval("IsReferralRequired")) = False), "No", "Yes")%>