Conversion from type 'DBNull' to type 'Boolean' is not valid.

how do u handle it in this case
Dim cholo As Boolean = CType(DataBinder.Eval(e.Row.DataItem, "morning"), Boolean)


_________this is the code if needed____________
   If e.Row.RowType = DataControlRowType.DataRow Then
            Dim lnkFile As HyperLink = CType(e.Row.FindControl("lnkFile"), HyperLink)
            Dim image1 As Image = CType(e.Row.FindControl("image1"), Image)
            Dim cholo As Boolean = CType(DataBinder.Eval(e.Row.DataItem, "morning"), Boolean)
            If cholo = True Then
                image1.visible = True
            Else
                lnkFile.Visible = True
               
            End If
        End If
LVL 1
gianitooAsked:
Who is Participating?
 
Raju SrivatsavayeConnect With a Mentor Software EngineerCommented:
 If e.Row.RowType = DataControlRowType.DataRow Then
            Dim lnkFile As HyperLink = CType(e.Row.FindControl("lnkFile"), HyperLink)
            Dim image1 As Image = CType(e.Row.FindControl("image1"), Image)
            Dim cholo As Boolean = False
           if not IsDBNULL(DataBinder.Eval(e.Row.DataItem, "morning") ) then
                     cholo = CType(DataBinder.Eval(e.Row.DataItem, "morning"), Boolean)
             end if
            If cholo = True Then
                image1.visible = True
            Else
                lnkFile.Visible = True
               
            End If
        End If
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.