开发者

Binding nullable bit database column to CheckBox in GridView - crash when null

I'm trying to bind a nullable bit column, which at the moment is mostly null, but I need to somehow convert the null to a 'false' on runtime because it doesn't bind to a checkbox if it's null. But, I am开发者_开发知识库 currently unable to change the default value and update all records accordingly - is there a way to do this in runtime?


You can change your select to use ISNULL(bit_column, 0). This way it will always have a value of false that you can bind to, even when the column has a null value in the database.


If you are reading it from a DataRow in a DataTable then you can do the following:

dataRow.Field<bool?>("ColumnName") ?? false;


It can be done using a template field in the GridView like:

'<%# Eval("ColumnName") ?? false %>'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜