Checkbox in editform

11 posts, 0 answers
  1. aykut
    aykut avatar
    64 posts
    Member since:
    Oct 2007

    Posted 15 Jun 2008 Link to this post

    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.
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 16 Jun 2008 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Pablo
    Pablo avatar
    11 posts
    Member since:
    Jul 2008

    Posted 02 Aug 2008 Link to this post

    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.
  5. Yavor
    Admin
    Yavor avatar
    11 posts

    Posted 04 Aug 2008 Link to this post

    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.
  6. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 04 Aug 2008 Link to this post

    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.
  7. Eric Downey
    Eric Downey avatar
    52 posts
    Member since:
    Oct 2006

    Posted 01 Dec 2009 Link to this post

    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
  8. aykut
    aykut avatar
    64 posts
    Member since:
    Oct 2007

    Posted 02 Dec 2009 Link to this post

    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")) %>' />

     

  9. Eric Downey
    Eric Downey avatar
    52 posts
    Member since:
    Oct 2006

    Posted 02 Dec 2009 Link to this post

    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
  10. aykut
    aykut avatar
    64 posts
    Member since:
    Oct 2007

    Posted 02 Dec 2009 Link to this post

    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
       

  11. Eric Downey
    Eric Downey avatar
    52 posts
    Member since:
    Oct 2006

    Posted 02 Dec 2009 Link to this post

    Excellent!  That IS the answer!  My checkboxes are working now - awesome!

    Thanx,

    Eric
  12. Jon
    Jon avatar
    2 posts
    Member since:
    Nov 2011

    Posted 01 Oct 2014 Link to this post

    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"


Back to Top
UI for ASP.NET Ajax is Ready for VS 2017