Recently updated my project with v2022.2 from v2017.2 components. In the past, no issues, simple upgrade and publish. However, something changed and I can't seem to put my finger on it. It may just be staring me in the face.
To isolate if it's something in the old page/code, I created a single page with a WebDataGrid with a single UnboundCheckbox. I run a query, bind it then set the value of the checkbox. I use session variables (a lot). So, immediately AFTER issuing a .DataBind I execute this line:
Me.wgTestCheckBox.Rows(0).Items(0).Value = CBool(Session("Grant_Svc"))
In the past, it worked fine. Now it throws an "Invalid Cast" error. Keep in mind the value being assigned to the checkbox is boolean. I've gone back and forth with this, modifying the view to convert the source text column to boolean, no success, So I revert the value in the database view back to text and doing as above (which currently works in the old project).
Regardless, of how I approach it, I continue to get "Invalid Cast" error. WHAT AM I NOT SEEING, or did something change with UnboundCheckBoxes since 2017.2?
Hi Robert,
The issue doesn’t seem to be stemming from the UnboundCheckboxes but instead from the way VB converts types. To convert a string value into a boolean you’ll need to use the “Convert.ToBoolean(string stringName)” method.
Example: WebDataGrid1.Rows(0).Items(1).Value = Convert.ToBoolean(Session("true"))
Hope this helps. Please let me know if you need any further assistance regarding this matter.
Regards,
Aleksandar Atanasov,
Infragistics.
Actually this threw the same error, but it made me look at the problem differently. I found that I had used column names that are in the actual query that fills the control as keys. Those columns come in as text. So, what I figured the problem was that it was trying to put a boolean into a string which was tied to a boolean unboundcheckbox. So, the system was "confused".
In the end, the solution was to just change the keys to names that didn't exist, THEN assign the converted string to boolean values. It worked! Odd, but it just showed that something had changed in the last five plus years.
Thank you for your assistance!
Hello Robert,
I am glad that you managed to achieve your requirement. Thank you for using Infragistics components.