locked
setting field to Nulls not working - LINQ datasource with Listview RRS feed

  • Question

  • User438705957 posted

    I have a Listview with a LinqDataSource.
    I am allocating a resoure called Bladder Scanners to clinicians on the day selected. The field in the database, 'Allocated_Bladder_Scanner_Id', allows nulls.
    The 'nullable' property of the field in the dbml is set to allow nulls.
    In the edit template, I have an unbound dropdownlist (drpBladderScannerDropdown) with an 'empty string' item added to cater for nulls, and AppendDataBoundItems="true".
    In order to show only bladder scanners which have not yet been allocated on the selected day, I am databinding the dropdownlist to a dictionary of unallocated bladder scanners in the ItemDataBound event. I then add the currently selected bladder scanner as a listitem and set it as the selected item.
    So far, so good, all works well.

    However, if the clinician has a bladder scanner currently allocated, and then the user elects to not allocate the clinician a bladder scanner on that day by selecting 'Nothing' from the dropdownlist, the LinqDataSource fails to update the field. It does not throw an exception, it just doesn't set the field to nulls.
    In ItemUpdating I have the following code:

    Dim drpBladderScannerDropdown As DropDownList = CType(ListView1.Items(e.ItemIndex).FindControl("drpBladderScannerDropdown"), DropDownList)
            If drpBladderScannerDropdown.SelectedValue = String.Empty Then
                e.NewValues("Allocated_Bladder_Scanner_Id") = CType(Nothing, Nullable(Of Byte))
            Else
                e.NewValues("Allocated_Bladder_Scanner_Id") = drpBladderScannerDropdown.SelectedValue
                Resource_Allocated = True
            End If

    Thanks

     

     

    Thursday, January 6, 2011 5:22 PM

All replies

  • User3866881 posted

    Try:

      e.NewValues("Allocated_Bladder_Scanner_Id") = Nothing

    Or

     e.NewValues("Allocated_Bladder_Scanner_Id") = DbNull.Value

    Wednesday, January 19, 2011 10:26 PM