Difficult Checkbox question

Been going round and round for a few days on this...

The Telerik RadGrid can be used with a built in edit form.

I've built it and It works for all updates or edits.

However...there is a problem with the INSERT portion because the checkboxes now are trying to handle a dbnull.

Inside the edit form...
<asp:CheckBox ID="ckMaintenance" Checked='<%# Bind("maintenance")  %>'  runat="server" />

Is there any way to use the BIND (Eval inserts empty strings on edit or insert)  with my attached function for handling nulls?

I can't figure out how to apply the Telerik explanation at http://www.telerik.com/help/aspnet-ajax/grdinsertingvaluesusercontrolformtemplate.html 
Public Function TrueOrFalse(ByVal dbValue As Object) As Object
        If dbValue.GetType Is DBNull.Value.GetType Then
            Return False
        Else
            Return Convert.ToBoolean(dbValue)
        End If
    End Function

Open in new window

Larry Bristersr. DeveloperAsked:
Who is Participating?
 
AshokCommented:
If any of above is not working, follow

<asp:CheckBox ID="chkEnabled" runat="server" Checked='<%# (DataBinder.Eval(Container.DataItem,"Status") is DBNull ?false:Eval("Status")) %>' TabIndex="1" />  

Read complete thread at

http://www.telerik.com/community/forums/aspnet/grid/asp-checkbox-in-formtemplate-specified-cast-is-invalid.aspx

Ashok

0
 
AshokCommented:
Try

Public Function TrueOrFalse(ByVal dbValue As Object) As Object
        If dbValue == System.DBNull.Value Then
            Return False
        Else
            Return Convert.ToBoolean(dbValue)
        End If
End Function

Ashok


0
 
Larry Bristersr. DeveloperAuthor Commented:
ashok111:
How do I wrap the checkbox Checked='' tage to access this?
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
AshokCommented:
Do you mean TAG (not tage)?

Or

You want to assign third value (not true and not false)?

Ashok
0
 
AshokCommented:
Try

Public Function TrueOrFalse(ByVal dbValue As Object) As Object
        If IsDBNull(dbValue) Then
            Return False
        Else
            Return Convert.ToBoolean(dbValue)
        End If
End Function

Ashok


0
 
Larry Bristersr. DeveloperAuthor Commented:
ashok111:
 I mean...how do I use the function with the checkbox?
<asp:CheckBox ID="ckMaintenance" Checked='<%# Bind("maintenance")  %>'  runat="server" />
 
0
 
AshokCommented:
Try

<asp:CheckBox ID="CheckBox11" runat="server" Checked='<%# IIf(Eval("maintenance") Is DBNull.Value, "False", Eval("maintenance")) %>' />

HTH
Ashok
0
 
AshokCommented:
Try

<asp:CheckBox ID="CheckBox11" runat="server" Checked='<%# IIf(Eval("maintenance") Is DBNull.Value, "", Eval("maintenance")) %>' />

HTH
Ashok
0
 
AshokCommented:
Try

<asp:CheckBox ID="CheckBox11" runat="server" Checked='<%# TrueOrFalse("maintenance") %>' />

and

Public Function TrueOrFalse(ByVal dbValue As Object) As Object
        If IsDBNull(dbValue) Then
            Return Null
        Else
            Return Convert.ToBoolean(dbValue)
        End If
End Function

HTH
Ashok
0
 
Larry Bristersr. DeveloperAuthor Commented:
I found my own solution..

Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand 
If (e.CommandName = RadGrid.InitInsertCommandName) Then 
e.Canceled = True 
Dim newValues As System.Collections.Specialized.ListDictionary = New System.Collections.Specialized.ListDictionary() 
newValues("maintenance") = False 
newValues("active") = False 
e.Item.OwnerTableView.InsertItem(newValues) 
End If 
End Sub

Open in new window

0
 
Larry Bristersr. DeveloperAuthor Commented:
Thanks for sticking with this.
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.