Casting Eval("bitValue") as Bool

If Locked is an int you should do this:

<%# ((int)Eval("Locked")) == 1 ? true : false %>

But then this should work too, so it returns true when Locked > 0

<%# !((int)Eval("Locked") == 0) %>

No matter it is mentioned that Locked contains 0 or 1. It is still an INT which can for some reason contain values > 1. Therefore i find it good practice to do the check on == 0 instead of == 1. We don't know what Locked is used for and in the future the design could change so that Locked can contain a value > 1.


SQL is a strange world where bits can have three states 0, 1 and null! So this means that Eval("Locked") is a nullable type bool, not a plain bool A cast to bool will not be valid if the bit value is null, you have to check that first:

(Eval("Locked")!=null && (bool)Eval("Locked")==true)

This assumes that null should be mapped to false.


Checked='<%# Eval("SEND_EMAIL") == DBNull.Value ? false : Convert.ToBoolean(Eval("SEND_EMAIL")) %>'