This is a migrated thread and some comments may be shown as answers.

Checkbox in editform

10 Answers 723 Views
Grid
This is a migrated thread and some comments may be shown as answers.
aykut
Top achievements
Rank 1
aykut asked on 15 Jun 2008, 09:18 AM
Please somebody help me about using simple checkbox in edit forms. I always get famous DBnull error. I need simple sample using sql server and data type integer. I spent more than one week and still no result. when I correct update events, then addnew throws error. when I correct addnew part, orher parts fail. I tried everything on sql site. int column type, bit column type, nullable, everything. I tried to change combobox to get rid of checkbox, another selected value, dbnull, etc etc errors rise. I won't give any error message, it is  famous problem.

Just need one column of RadGrid to add, and update record to sql table which has only one column with type of integer. I need it to use form templates.

Why this is so difficult.
best regards.

10 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 16 Jun 2008, 05:27 AM
Hi Aykut,

Try using a GridCheckBox column which will render a checkbox in the edit mode.

ASPX:
  <telerik:GridCheckBoxColumn UniqueName="CheckboxColumn" HeaderText="CheckboxColumn"  DataField="BooleanField"  DataType="System.Boolean" ></telerik:GridCheckBoxColumn> 

Shinu
0
Pablo
Top achievements
Rank 1
answered on 02 Aug 2008, 05:43 PM
He is not referring to the checkbox inside the RadGrid's Column's tag.
He is referring to a checkbox he is trying to place in the FormTemplate tag.
I am having the same trouble.
The GridCheckBoxColumn works greate to render a checkbox inside the grid, but when you clic "Add new record" an error is thrown, indicating that the value null is not a valid value for the checkbox "checked" property.
I have tried Bind, Eval, and it won't work.
Here is my code:
<asp:CheckBox ID="Activada" runat="server" Checked='<%# Bind("Activada") %>' /> 

I hope you can help us, I haven't seen a solution to this in any post, or any examples from you, and it is a very basic and common situation.

Thanks in advance.
0
Yavor
Telerik team
answered on 04 Aug 2008, 05:05 AM
Hello Pablo,

When the control is in edit mode, the value for the column in question is null, since no value exists yet. Hence, the issue with the binding expression. One possible approach would be to remove the Binding expression, and set the checked/unchecked status from the code-behind. Alternatively, you can conditianally determine if the item is a GridEditFormInsertItem (i.e. the grid is in insert mode):

'<%# (Container is GridEditFormInsertItem) ? "TrueStatement" : "FalseStatement" %>'

I hope this information helps.

Sincerely yours,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Princy
Top achievements
Rank 2
answered on 04 Aug 2008, 06:09 AM
Hi guys,

I'm not sure if this would solve your problems but I found a forum link which explains a similar kind of scenario.
Checkbox in FormTemplate- "Specified Cast is Invalid"

Hope this helps atleast to some extent.

Thanks
Princy.
0
Eric Downey
Top achievements
Rank 1
answered on 02 Dec 2009, 03:27 AM
Hi Folks,

I've been hunting down the answer to this one for awhile.  I ended up dropping it awhile ago and not doing an in grid edit.  I've come back around now in another project and would really like to be able to use a checkbox in a <formtemplate> in a <RadGrid>.  Does ANYONE know of a known working solution to this?  I've tried all of the above suggestions and even participated in the thread that is listed above.  Is there an example in the code examples that Telerik supplies?  I can't seem to find it and this is a fairly important thing to not be able to do.

Thanx,
Eric
0
aykut
Top achievements
Rank 1
answered on 02 Dec 2009, 07:50 AM
Here's the solution that works in my project:


<

 

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

 

0
Eric Downey
Top achievements
Rank 1
answered on 02 Dec 2009, 01:19 PM
Do you use that in an edit form in the grid?  I thought Eval was only good for displaying info.  If you wanted to get the full edit capability you had to use a Bind.

Thanx,

Eric
0
aykut
Top achievements
Rank 1
answered on 02 Dec 2009, 03:06 PM

I use

<asp:CheckBox ID="chkOnaylandi" runat="server" Checked='<%# Bind("Onaylandi") %>' />

in form template and

Private 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 New System.Collections.Specialized.ListDictionary()
            newValues("Onaylandi") = 0
            e.Item.OwnerTableView.InsertItem(newValues)
        End If
    End Sub

in the code side. and I bont deal with dbnull values... Onaylandi field id integer in sqlserver
   

0
Eric Downey
Top achievements
Rank 1
answered on 02 Dec 2009, 05:46 PM
Excellent!  That IS the answer!  My checkboxes are working now - awesome!

Thanx,

Eric
0
Jon
Top achievements
Rank 1
answered on 01 Oct 2014, 03:25 PM
I know this is an old post, but I came across the same issue recently and solved it in a similar way, except I had to set my value to false rather than 0.

Here's the C# code I used:
    protected void rgUserRequest_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e) 
    {
        if (e.CommandName == RadGrid.InitInsertCommandName)
        {
            e.Canceled = true;
            System.Collections.Specialized.ListDictionary newValues = new System.Collections.Specialized.ListDictionary();
            newValues["Purchased"] = false;
            e.Item.OwnerTableView.InsertItem(newValues);
        }
    }


I also had to add the following to my grid control: OnItemCommand="rgUserRequest_ItemCommand"


Tags
Grid
Asked by
aykut
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Pablo
Top achievements
Rank 1
Yavor
Telerik team
Princy
Top achievements
Rank 2
Eric Downey
Top achievements
Rank 1
aykut
Top achievements
Rank 1
Jon
Top achievements
Rank 1
Share this question
or