Bind checkbox in Template Column

26 posts, 0 answers
  1. Jimmy Stuart
    Jimmy Stuart avatar
    71 posts
    Member since:
    Mar 2006

    Posted 04 Mar 2008 Link to this post

    I have a weird issue that appears to have cropped up after switching from a regular RadGrid to the Prometheus Rad Grid (3.1425 release).  I have several check boxes in a template column and am using the automatic databinding:

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

    This worked fine on the old grid.  But on the new Prometheus one I get the following error:

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

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.InvalidCastException: Conversion from type 'DBNull' to type 'Boolean' is not valid.

    Source Error:

    Line 173:							<br />
    Line 174:							Is Public?
    Line 175: <asp:CheckBox ID="PublicCheckBox" Checked='<%#Bind("IsPublic") %>' runat="server" />Line 176:							<br />
    Line 177:							Folder:


    What's weird is that this only occurs when I try to insert a record.  Editing an existing record works fine.  There are a total of 3 Boolean columns in the database table ALL of which do NOT allow Null and have a default value of False (or 0).  Also this error occurs whether or not the grid is Ajaxified with the Prometheus RadAjaxManager.  Again, I'm using all automatic datasource operations and the datasource controls and the data is the same that worked just fine with the old Rad Grid.  Is there anything in the new grid that would cause this?

    Thanks,

    Jimmy

  2. John
    John avatar
    416 posts
    Member since:
    Oct 2006

    Posted 06 Mar 2008 Link to this post

    hi



    You have to set predefine value on init insert to avoid the problem. Review the last paragraph of this documentation topic:


    http://www.telerik.com/help/aspnet/grid/?grdInsertingValuesInPlaceAndEditForms.html


    Regards...
    <John:Peel />
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Simon
    Simon avatar
    2 posts
    Member since:
    Apr 2008

    Posted 13 May 2008 Link to this post

    I have this same problem.  John's solution worked.  I added this code-behind:

    Partial

    Public Class BusinessAssociateList

    Inherits System.Web.UI.Page

    Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As GridCommandEventArgs) Handles RadGrid1.ItemCommand

    If (e.CommandName = RadGrid.InitInsertCommandName) Then

    'cancel the default operation

    e.Canceled = True

    'Prepare an IDictionary with the predefined values

    Dim newValues As System.Collections.Specialized.ListDictionary = New System.Collections.Specialized.ListDictionary()

    'set default value for the dropdown list inside the EditItemTemplate

    newValues("Status") = "ACTIVE"

    'set default checked state for checkbox inside the EditItemTemplate

    newValues("DunnsPrimaryFlag") = True

    'Insert the item and rebind

    e.Item.OwnerTableView.InsertItem(newValues)

    End If

    End Sub

    End

    Class


    Notice how this is the ONLY code behind my asp page.  Everything is declarative, except the default values for the newly inserted item.  It seems like this is a bug or missing feature in the new grid.  Isn't it?  I have a medium complexity grid, pulling data from an objectdatasource, and it is editable using a Template form with drop downs and a checkbox.  The checkbox is the only control that errors.  And this code behind solves the problem.  However, this code behind seems to be a work around. 
    I think the GridColumn should have a DefaultValue propery that can be set declaritively and which is then used to initialize newly inserted rows.

  5. jonnyO
    jonnyO avatar
    53 posts
    Member since:
    Jan 2004

    Posted 28 Jun 2008 Link to this post

    Cheers to you Simon... like the DbSelectDate for DatePicker...
  6. Steve Newbery
    Steve Newbery avatar
    103 posts
    Member since:
    Apr 2005

    Posted 22 Aug 2008 Link to this post

    "The checkbox is the only control that errors.  And this code behind solves the problem.  However, this code behind seems to be a work around. 
    I think the GridColumn should have a DefaultValue propery that can be set declaritively and which is then used to initialize newly inserted rows."

    I completely agree - this seems a "kludge" and is a bit annoying really. Can you please consider this for the next release of radGrid?

  7. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 22 Aug 2008 Link to this post

    Hi Steve Newbery,

    Have you tried using grid specific column instead of GridTemplate column? For instance, GridCheckBoxColumn, GridDropDownColumn, GridDateTimeColumn, Give it a try and check if the problem persists.
    Find more about RadGrid column type here.

    Greetings,
    Iana
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  8. Steve Newbery
    Steve Newbery avatar
    103 posts
    Member since:
    Apr 2005

    Posted 22 Aug 2008 Link to this post

    Iana, yes I have, and using GridCheckBoxColumn I don't have this problem.

    But, I have to refer to the column's ID from a validator, and I don't see how to do this when the column is a grid specific column.

    So if I have:

    <telerik:GridCheckBoxColumn UniqueName="MailExtract" HeaderText="MailExtract" 
          DataField="MailExtract">  
    </telerik:GridCheckBoxColumn> 

    what then is the ID of the control? I need to refer to it in my validator: 

    <des:RequiredTextValidator runat="server" 
        ID="EmailRequiredTextValidator"   
        ControlIDToEvaluate="EmailTextBox"   
        ErrorMessage="This field is required if MailExtract is checked">  
        <EnablerContainer> 
            <des:CheckStateCondition ControlIDToEvaluate="MailExtractCheckBox" /> 
        </EnablerContainer> 
    </des:RequiredTextValidator> 
     

    Thanks for any help, Steve
  9. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 25 Aug 2008 Link to this post

    Hi Steve,

    Thank you for the additional information.

    You may consider assigning the ControlIDToEvaluate property of your custom validator dynamically intercepting the ItemCreated event of the grid. The code implementation from the first section of this help topic can get you started:

    http://www.telerik.com/help/aspnet-ajax/grdvalidation.html

    Let me know if I am missing something from your logic.

    Best regards,
    Stephen
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  10. Carl
    Carl avatar
    195 posts
    Member since:
    Oct 2012

    Posted 30 Nov 2008 Link to this post

    I just experienced the exact problem described in the first post in this thread. A checkbox in a GridTemplateColumn. Works great when editing existing records but bombs when inserting a new record, again with the same error as described in the first post of this thread.

    So I agree. It seems an unnecessary added complexity to be obligated to write some code-behind just to handle some simple defaults for a boolean on a checkbox that easily could be set to default to false by the Telerik assembly. Please add my vote to the other requests to fix this problem in the next release of RadGrid.

    In general, all of the controls in the Telerik RadGrid assembly should have basic defaults like this already built in. It does not make sense to have this great wonderful powerful RadGrid, and then have to waste time tracking down errors (and/or writing extra unnecessary code-behind) just to handle missing defaults that should be automatically built into the released Telerik assembly.

    Thank you for prioritizing for next release.

    CT
  11. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 01 Dec 2008 Link to this post

    Hello Carl,

    Thank you for your feedback - I will forward it to our dev team to be considered for the future versions of the product. Additionally, I will appreciate if you provide some pointers about online resources which elaborate on this subject or other web grids which has the requested functionality built-in. Thus we will be able research the matter in more detail.

    Best regards,
    Sebastian
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  12. Carl
    Carl avatar
    195 posts
    Member since:
    Oct 2012

    Posted 01 Dec 2008 Link to this post

    I do not understand the request for pointers on this matter to other webgrids etc that have the desired functionality.

    This matter is fundamental and basic. If any developer creates any web form of any kind, then the web form should be designed so that it initializes without bombing out because of some silly error that results from a variable or class not being initialized to a reasonable and sensible initial default value. So for booleans, just initialize to false if that's what makes sense, but do not leave it uninitialized (null or nothing) so that the whole web form blows up. This matter is that simple. There's no need to research anything here.

    Conclusion: controls for web forms designed and developed for release with the Telerik assembly should be properly coded with appropriate initial default values so that the web forms do NOT blow up!!!
  13. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 02 Dec 2008 Link to this post

    Hi Carl,

    Thank you for the additional explanation - your feedback has already been forwarded to our RadGrid development department to be considered for the upcoming versions of the product. In the meantime I hope that setting a predefined value for the boolean field intercepting the init insert command is feasible for your situation.

    Kind regards,
    Sebastian
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  14. jimmie
    jimmie avatar
    9 posts
    Member since:
    Jan 2009

    Posted 15 Jun 2009 Link to this post

    When i tried this code it threw an exception 

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

    At the insert line

     

     

     

     

     

    e.Item.OwnerTableView.InsertItem(newValues)

  15. Keith Heilveil
    Keith Heilveil avatar
    29 posts
    Member since:
    May 2005

    Posted 30 Oct 2009 Link to this post

    Yes I'm reviving this thread. I vote it be fixed, as the developer should be able to expect the controls to at least set their default values without bombing on an Add.
  16. Shawn Krivjansky
    Shawn Krivjansky avatar
    86 posts
    Member since:
    Jan 2010

    Posted 09 May 2010 Link to this post

    Another vote to fix.
    Just wasted an hour chasing this around.
    FYI, I am on the 2010 Q1 415 (SP1) release, so it hasn't been fixed to this point.
  17. Shawn Krivjansky
    Shawn Krivjansky avatar
    86 posts
    Member since:
    Jan 2010

    Posted 09 May 2010 Link to this post

    Actually, just found the missing property that gets around this...didn't notice it before.
    On GridTemplateColumn:
    "DefaultInsertValue"
    This will make things NOT blow up like it had previously (without the property set).

     

    <telerik:GridTemplateColumn HeaderText="TM" HeaderButtonType="TextButton" 
                                DataField="isTaskManager" UniqueName="isTaskManager"   
                                SortExpression="isTaskManager" 
                                HeaderStyle-Width="25" DataType="System.Boolean" DefaultInsertValue="False"

     

     

     


     

  18. Joshua Warren
    Joshua Warren avatar
    6 posts
    Member since:
    May 2010

    Posted 10 Jun 2010 Link to this post

    I tried this, and for the most part it worked.  The only problem is that when the add button/text is clicked, it goes to the last page in the pagination.  All of the controls that are supposed to come up do, it just goes to the last page.  Is there any way to keep this from happening??  Can I capture the page that I am on when the add button is pressed, and then set it back to that page?

    Thanks in advance,

    -- joshua
  19. Joshua Warren
    Joshua Warren avatar
    6 posts
    Member since:
    May 2010

    Posted 10 Jun 2010 Link to this post

    Also, if you are in the adding mode, and you try to change pages, it will then throw the original error of "Conversion from type 'DBNull' to type 'Boolean' is not valid. 
  20. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 11 Jun 2010 Link to this post

    Hello Joshua,

    Try the following code snippet and see whether this helps you.

    ASPX:
    <telerik:GridTemplateColumn> 
         <EditItemTemplate> 
              <asp:CheckBox ID="CheckBox1" Checked='<%# (DataBinder.Eval(Container.DataItem,"isapproved") is DBNull ?false:Eval("isapproved")) %>' runat="server" /> 
         </EditItemTemplate> 
     </telerik:GridTemplateColumn> 

    Regards,
    Shinu.



  21. Joshua Warren
    Joshua Warren avatar
    6 posts
    Member since:
    May 2010

    Posted 14 Jun 2010 Link to this post

    Shinu,

       Thank you for your response.  It didn't quite work, but got me on the right path.  I ended up finding some code that worked:

    <asp:CheckBox ID="chbx_Active" runat="server" checked='<%# IF(Eval("lp_active") is DBNull.Value, False, Eval("lp_active")) %>'/>  
     

     

    Thanks, again!

    -- Joshua

     

     

     

     


     

     

  22. sroussos
    sroussos avatar
    6 posts
    Member since:
    Nov 2009

    Posted 01 Dec 2012 Link to this post

    Worked for me!
  23. Angel Petrov
    Admin
    Angel Petrov avatar
    1006 posts

    Posted 01 Oct 2015 Link to this post

    Hello guys,

    I am happy to announce that we have integrated an improvement regarding this matter. With the latest 2015 Q3 official release an exception will not be thrown. Instead the default value of the boolean field will be set to false instead of DBNull.

    Regards,
    Angel Petrov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  24. Sonny
    Sonny avatar
    5 posts
    Member since:
    Jun 2014

    Posted 02 Oct 2015 in reply to Angel Petrov Link to this post

    I have downloaded the Telerik_UI_for_ASP.NET_AJAX_Setup_2015_3_930.zip file and cannot extract it. I am getting an error that says it is an invalid archive.

    I cannot use the .exe or the .msi files because I do not have local admin rights on the development computer. 

     

  25. Marin Bratanov
    Admin
    Marin Bratanov avatar
    3595 posts

    Posted 04 Oct 2015 Link to this post

    Hello Sonny,

    I would suggest downloading the file again, the most likely reason for such a problem is a connectivity issue that has prevent the zip from downloading properly.

    Alternatives I can suggest are:

    • see if you can install the Telerik Control Panel on you machine as it can help with downloads/installations
    • consider reaching out to your network administrators so they can assist with ensuring the archive is downloaded properly
    • look for the "hotfix" archive that contains only the dlls, scripts, skins and resources as it is smaller and it is more likely to download successfully
    • open a support ticket so we can send you the assemblies at least until you can get them from our site

    On a side note - I would suggest opening separate threads for separate issues. Adding posts that are not related to the original subject is likely to dilute the thread and make information harder for everyone to find in it.

    Regards,

    Marin Bratanov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  26. Neha
    Neha avatar
    6 posts
    Member since:
    Feb 2013

    Posted 08 Feb in reply to John Link to this post

    Hi John,

     I have an issue with checkbox in radgrid. I have a checkbox defined in radgrid with a server side event :

    <asp:CheckBox ID="CheckBox1" runat="server" Commandname="RowClick" OnCheckedChanged="ToggleRowSelection"
    AutoPostBack="True" />

    This changes the row color when the corresponding checkbox is clicked.

    This code was working fine till I upgraded from .net 2.0 to .net 4.0

    Now this gives an error while rendering the checkbox. I am attaching screenshot of error.

    This error goes away when I remove the autopostback = true from the checkbox control. But then my server side event to toggle row selection is not fired.

    Following is the code snippet.

      <radG:RadGrid ID="RadGrid1" runat="server" EnableAJAX="true" EnableAJAXLoadingTemplate="true"
    AllowFilteringByColumn="false" LoadingTemplateTransparency="30" Skin="Outlook2007"
    Width="570px" PageSize="7" AllowSorting="True" AllowMultiRowSelection="True"
    AllowPaging="True" AllowCustomPaging="True" ShowGroupPanel="false" GridLines="None"
    AutoGenerateColumns="False" Height="230px" SkinsPath="../RadControls/Grid/Skins"
    OnItemCommand="RadGrid1_ItemCommand">
    <PagerStyle Mode="NumericPages" Position="Bottom" CssClass="GridPager"></PagerStyle>
    <MasterTableView DataKeyNames="FacilityId" DataMember="Hotels" AllowMultiColumnSorting="False"
    Width="100%" TableLayout="Fixed" Name="Main">
    <Columns>
    <radG:GridTemplateColumn UniqueName="CheckBoxTemplateColumn">
    <ItemTemplate>
    <asp:CheckBox ID="CheckBox1" runat="server" Commandname="RowClick" OnCheckedChanged="ToggleRowSelection"
    AutoPostBack="True" />
    <%--<asp:CheckBox ID="CheckBox1" runat="server" Commandname="RowClick" OnCheckedChanged="ToggleRowSelection"/>--%>
    </ItemTemplate>
    <HeaderTemplate>
    <asp:CheckBox ID="headerChkbox" runat="server" enabled="true" OnCheckedChanged="ToggleSelectedState"
    AutoPostBack="True" />
    </HeaderTemplate>
    <ItemStyle Width="20px" />
    <HeaderStyle Width="20px" />
    </radG:GridTemplateColumn>

  27. Angel Petrov
    Admin
    Angel Petrov avatar
    1006 posts

    Posted 11 Feb Link to this post

    Hi,

    Changing the .NET version should not cause such behavior. Can you please send us a sample which illustrates the problem?

    Additionally please try out the following.
    1. If the application uses AJAX please disable it and test whether a server-side exception is thrown.
    2. Verify that there are no scripts that have failed to load.

    Regards,
    Angel Petrov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017