Zero-bit database column binding in CheckBox in GridView - crash on error

I am trying to associate a column with a zero bit, which is currently mostly null, but I need to somehow convert the null value to false at runtime since it does not bind to the checkbox if it is zero. But at the moment, I cannot change the default value and update all records accordingly - is there a way to do this at runtime?

+3
source share
3 answers

You can change your choice to use ISNULL(bit_column, 0). That way, it will always be false, which you can bind to even if the column has a null value in the database.

+3
source

If you are reading it from a DataRow to a DataTable, you can do the following:

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

This can be done using the template field in the GridView, for example:

'<%# Eval("ColumnName") ?? false %>'
+1
source

Source: https://habr.com/ru/post/1776713/


All Articles