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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AshokSr. Software EngineerCommented:
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
AshokSr. Software EngineerCommented:
Do you mean TAG (not tage)?

Or

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

Ashok
0
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

AshokSr. Software EngineerCommented:
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
AshokSr. Software EngineerCommented:
Try

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

HTH
Ashok
0
AshokSr. Software EngineerCommented:
Try

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

HTH
Ashok
0
AshokSr. Software EngineerCommented:
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
AshokSr. Software EngineerCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Larry Bristersr. DeveloperAuthor Commented:
Thanks for sticking with this.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.