locked
how to show nullable checkbox in view RRS feed

  • Question

  • User-1257308419 posted

    i have this need where i will be displaying data in table format...now the data is coming  from a table where the default value is null for checkbox column.

    what i simply want to do is that show all the records with column value null and display a Unchecked(Checkbox) in a view.

    if i click on checkbox(i.e checkbox is checked) then i want to pass true.

    if i leave the checkbox as it is(i.e blank)then i want to pass false.

    but first i need to show all the null value rows from the table.

    is it possible to do so?

    here is my view

    all i want is to show the records from the table that have null values and when i submit the form with Approve button then store true for checked checkboxes rows and false for unchecked checboxes 

    Friday, September 11, 2020 3:21 AM

All replies

  • User-474980206 posted

    a checkbox checked property is true or false, and a checkbox binds to bool. to bind to bool? you need a dropdown with three states, true, false, null.

    but when you build the view model you can use bool and coalesce a null to false.

         boolProperty = boolNullableProperty ?? false;

     

    Friday, September 11, 2020 7:30 PM
  • User1686398519 posted

    Hi Learner94, 

    You can use jquery to set the checkbox not to be selected.

    $(document).ready(function () {
        $("#tblCustomers").find('input:checkbox[name*="userPackage.PackageStatus"]').prop('checked', false);
    });

    Best Regards,

    YihuiSun

    Tuesday, September 15, 2020 8:41 AM