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:
|
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
25 Answers, 1 is accepted
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 />
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.
"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?
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.
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
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.
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
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.
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!!!
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.
Conversion from type 'DBNull' to type 'Boolean' is not valid.
At the insert line
e.Item.OwnerTableView.InsertItem(newValues)
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.
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"> |
Thanks in advance,
-- 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.
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
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
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.
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,
Telerik
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>
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.
- If the application uses AJAX please disable it and test whether a server-side exception is thrown.
- Verify that there are no scripts that have failed to load.
Regards,
Angel Petrov
Telerik